CUnit icon indicating copy to clipboard operation
CUnit copied to clipboard

Isolate every test cases that are in a single test method

Open walterlv opened this issue 6 years ago • 0 comments

The test cases in a single test method may capture common variables in the method header. So a test case may affect each other.

public void Foo()
{
    var a = 1;

    "Test case 1".Test(() =>
    {
        a++;
        Assert.AreEqual(a, 2);
    });

    "Test case 2".Test(() =>
    {
        a++;
        Assert.AreEqual(a, 2);
    });
}

I recommend isolating every test cases that are in a single test method.

walterlv avatar Feb 28 '18 11:02 walterlv