none
Unable to run unit tests RRS feed

  • Question

  • Hi, I am new to unit testings, I am using the default VS unit test framework. I have two unit tests I want to run:

     [TestClass()]
        public class EmployeeTreeTests
        {
            [TestMethod()]
            public void RemoveEmployeeEnteryPointTest()
            {
               //content...
                bool Test = //condition
                Assert.IsFalse(Test);
            }
            [TestMethod()]
            public void RemainAtMemory()
            {
               //content...
                bool Test = //condition
                Assert.IsTrue(Test);
            }
        }

    The problem is not with the unit test themself, It just that one of them (RemoveEmployeeEnteryPointTest) won't even run, even when I click "run all" and even if I click specifically on this unit test and then click run, it just won't run, not displaying X or V icon, instead displaying the "!" icon (means that the unit test did not run yet) I don't know what have I done wrong, can it do with the fact I have extensions installed ( or some VS bug ?) I use the last version of VS community. How can I run both of my unit test properly?

     note: if you see similar qustion, I have asked in the wrong forum, so this is why there is duplicate of it

    • Edited by avivgood Tuesday, October 22, 2019 8:08 PM
    Tuesday, October 22, 2019 7:57 PM

Answers

  • Hi avivgood,

    Thank you for posting here.

    After checking the codes and pictures you shared here, I tried to test and reproduce your issue in my side.

    I create a simple class library project and add a unit test project to test. Use whole codes that you shared and just fill the condition or content you annotate. But everything work well when I click Run All Tests button.

    I notice that one of your method could run but the other could not. So I suppose if there are some configurations that not be configured well or the codes of (RemoveEmployeeEnteryPoint) method might affect the test to run.

    Do you install and use some nugget packages or install some other extensions? Please start VS in Safe Mode to prevent all third-party plugins and check this. (Close VS and open “Developer Command Prompt for VS 2019” then type devenv /SafeMode in command prompt)

    Not sure if there are some relationships between this two methods. For example, if one method run then the other will not run. Or one of the method will run after some operations have been done.

    If possible, could you share us with more codes about RemoveEmployeeEnteryPoint method or a simple sample (upload via OneDrive, Github) and this will be helpful for us to check.

    We are looking forward to hearing from you.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Now it is working (even tho I did not change anything)
    Wednesday, October 23, 2019 7:26 PM

All replies

  • Hi avivgood,

    Thank you for posting here.

    After checking the codes and pictures you shared here, I tried to test and reproduce your issue in my side.

    I create a simple class library project and add a unit test project to test. Use whole codes that you shared and just fill the condition or content you annotate. But everything work well when I click Run All Tests button.

    I notice that one of your method could run but the other could not. So I suppose if there are some configurations that not be configured well or the codes of (RemoveEmployeeEnteryPoint) method might affect the test to run.

    Do you install and use some nugget packages or install some other extensions? Please start VS in Safe Mode to prevent all third-party plugins and check this. (Close VS and open “Developer Command Prompt for VS 2019” then type devenv /SafeMode in command prompt)

    Not sure if there are some relationships between this two methods. For example, if one method run then the other will not run. Or one of the method will run after some operations have been done.

    If possible, could you share us with more codes about RemoveEmployeeEnteryPoint method or a simple sample (upload via OneDrive, Github) and this will be helpful for us to check.

    We are looking forward to hearing from you.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 23, 2019 5:48 AM
  • Are you saying that the unit tests won't run because of a problem in the called method?  but the purpose of unit tests is for cases where the method don't work properly. If you believe the problem is in the method or the unit test itself, I will provide the code:

    unit test (full version) 

    public void RemoveEmployeeEnteryPointTest()
            {
                var tree = new EmployeeTree();
                var EmpNd = new EmployeeNodeClass(new Employee());
                var EmpNd2 = new EmployeeNodeClass(new Employee());
                tree.AddEmployeeEnteryPoint(null, EmpNd);
                tree.AddEmployeeEnteryPoint(EmpNd, EmpNd2);
                tree.RemoveEmployeeEnteryPoint(ref EmpNd, EmpNd2);
                bool Test = tree.Trees[0].Employees.Contains(EmpNd2);
                Assert.IsFalse(Test);
            }

    and the method itself:

     public bool RemoveEmployeeEnteryPoint(ref EmployeeNodeClass Manager, EmployeeNodeClass Employee)
            {
                foreach (var EmpNd in Manager.Employees)
                    if (RemoveEmployee(EmpNd, ref Manager, Employee))
                        return true;
                return false;
            }
    
            private bool RemoveEmployee(EmployeeNodeClass Current, ref EmployeeNodeClass Manager, EmployeeNodeClass Employee)
            {
                if (Current.Equals(Employee))
                {
                    Manager.Employees.Remove(Employee);
                    return true;
                }
                foreach (var EmpNd in Manager.Employees)
                    if (RemoveEmployee(EmpNd, ref Manager, Employee))
                        return true;
                return false;
            }
    I don't know a lot about configurations but I have deleted my last tests project and created a new one. I am also creating it using the unit test project generator of VS (In right click->create unit tests) so It can not be wrong. I have used safe mode still the same. 

    Wednesday, October 23, 2019 1:45 PM
  • Hi avivgood,

    Thank you for posting here.

    After checking the codes and pictures you shared here, I tried to test and reproduce your issue in my side.

    I create a simple class library project and add a unit test project to test. Use whole codes that you shared and just fill the condition or content you annotate. But everything work well when I click Run All Tests button.

    I notice that one of your method could run but the other could not. So I suppose if there are some configurations that not be configured well or the codes of (RemoveEmployeeEnteryPoint) method might affect the test to run.

    Do you install and use some nugget packages or install some other extensions? Please start VS in Safe Mode to prevent all third-party plugins and check this. (Close VS and open “Developer Command Prompt for VS 2019” then type devenv /SafeMode in command prompt)

    Not sure if there are some relationships between this two methods. For example, if one method run then the other will not run. Or one of the method will run after some operations have been done.

    If possible, could you share us with more codes about RemoveEmployeeEnteryPoint method or a simple sample (upload via OneDrive, Github) and this will be helpful for us to check.

    We are looking forward to hearing from you.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Now it is working (even tho I did not change anything)
    Wednesday, October 23, 2019 7:26 PM
  • Hi avivgood,

    Thank you for the feedback.

    Sorry for any of inconvenience and I am very glad to hear that your issue has been solved.

    Normally, there is no need to configure something and all the test will run after you click Run All Tests button.

    Anyway, sorry again and if possible, you could mark your reply as answer so that other members who have similar issue could refer to this thread.

    Wish you a nice day.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 24, 2019 7:36 AM