简体   繁体   中英

Different results in nUnit tests - run vs debug

In my project, I have overloaded function GetPrimeList(int max) and GetPrimeList(long max).

GetPrimeList(int max) is implemented correctly, but the one taking long as parameter should fail for numbers below 10 (at the moment);

I have written tests

[TestCase(1, 0)]
[TestCase(3, 1)]
public void GetPrimeList_ShouldReturnAllPrimesBelowGivenNumber(int max, int result)
{
    var primes = PrimeHelper.GetPrimeList(max);
    Assert.AreEqual(result, primes.Count);
}

[TestCase(1, 0)]
[TestCase(3, 1)]
public void GetPrimeList_ShouldReturnAllPrimesBelowGivenNumber(long max, int result)
{
    var primes = PrimeHelper.GetPrimeList(max);
    Assert.AreEqual(result, primes.Count);
}

Now when I run tests in normal mode they all pass, but when I run them in debug mode, test for long argument fails (as expected).

There is separate test project; when I call functions in original project I cannot reproduce behavior (tried to compare Release and Debug modes). I' ve also tried to turn off code optimization in my test project, but it didn't solve the problem.

Any idea how to fix my test project ?

Could you try to rename the last "GetPrimeList_ShouldReturnAllPrimesBelowGivenNumber" to something like "GetLongPrimeList_ShouldReturnAllPrimesBelowGivenNumber" and check it again? Just feeling that it can matter. My assumption is that in normal mode the latest test is not called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM