Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio does not run all the unit tests in a test class

I have 3 test methods in my unit test class, but Visual Studio only runs the second test, ignoring the others

These are the 3 test methods:

[TestClass()]
public class InsertionSortTest
{

    [TestMethod()]
    public void sortTest()
    {
        InsertionSort target = new InsertionSort(); // TODO: Initialize to an appropriate value
        int[] n = new int[] { 2, 1, 4 };
        int[] nExpected = new int[] { 1, 2, 4 };
        target.sort(ref n);
        CollectionAssert.AreEqual(nExpected, n);

    }

    [TestMethod()]
    public void sortTest2()
    {
        InsertionSort target = new InsertionSort(); // TODO: Initialize to an appropriate value
        int[] n = new int[] { 1, 2 };
        int[] nExpected = new int[] { 1, 2 };
        target.sort(ref n);
        CollectionAssert.AreEqual(nExpected, n);

    }

    [TestMethod()]
    public void sortTest3()
    {
        InsertionSort target = new InsertionSort(); // TODO: Initialize to an appropriate value
        int[] n = new int[] { 1, 2 };
        int[] nExpected = new int[] { 1, 2 };
        target.sort(ref n);
        CollectionAssert.AreEqual(nExpected, n);

    }
}

So when I run the test only sortTest2 is executed? I am expecting 3 results from this. I am getting Results 1/1 passed. TestName: sortTest2.

What happened with the other two tests I made?

like image 366
ganjan Avatar asked Oct 28 '12 16:10

ganjan


3 Answers

gillyb, yeah, you where right I think. Re-starting Visual Studio fixed the problem.

like image 141
ganjan Avatar answered Nov 15 '22 15:11

ganjan


I have noticed tests being shown as "not run" after test run completed. Turned out these tests were never completed due to a StackOverflowException being thrown mid way.

like image 41
Lars Pellarin Avatar answered Nov 15 '22 16:11

Lars Pellarin


Something that has bitten me more than once with this is that the test project was not checked to be built in the solution configuration.

like image 30
BlackICE Avatar answered Nov 15 '22 16:11

BlackICE