简体   繁体   English

nUnit测试中的结果不同-运行与调试

[英]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)和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); GetPrimeList(int max)的实现正确,但对于10以下的数字(此刻),需要花很长时间作为参数的数字会失败;

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? 您可以尝试将最后一个“ GetPrimeList_ShouldReturnAllPrimesBelowGivenNumber”重命名为“ GetLongPrimeList_ShouldReturnAllPrimesBelowGivenNumber”,然后再次检查吗? Just feeling that it can matter. 只是觉得这很重要。 My assumption is that in normal mode the latest test is not called. 我的假设是在正常模式下不会调用最新的测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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