开发者

Assert.Fail does not fail test?

开发者 https://www.devze.com 2023-01-12 13:06 出处:网络
I am using VS 2008 for unit testi开发者_如何转开发ng. Even if my code calls Assert.Fail(\"some message\");

I am using VS 2008 for unit testi开发者_如何转开发ng. Even if my code calls

Assert.Fail("some message");

Test passess ??

and even

Assert.IsTrue(false); this also passes test.

How is this possible. I am expecting test to fail . i want to forcefully fail it .

Please help !


Probably you are catching exceptions somewhere in the test code. Assert class uses exceptions to fail the test, so if you are catching it the test passes.

Please paste the code for more accurate answer.


Are you using the Assert class built into .NET? If so, I suspect TRACE was not defined.


Sometimes, when I click "run tests", I've seen the test engine build in Release configuration but then proceed to run tests against an older Debug configuration build. I would call that a bug in the VS2008 test engine. Anyway, try cleaning your Debug AND Release folders and running it again.


I can't be sure without knowing more about what you're doing, but it sounds like you're expecting the .NET classes to work like the NUnit classes -- can't be sure -- but if you are, that will never work.

The .NET classes only work if Trace is defined (view the Project Properties, the click the Build tab, then click the "Define TRACE constant"). -- But for Unit Tests this is not helpful -- those classes do not throw exceptions or otherwise fail unit tests... they pop up message boxes for those subscribing to the "debug later" mantra.

If you want Assert.Fail to fail a unit test you'll need a unit testing framework that provides a class which does this (again, like NUnit). Please, let us know what testing framework you're using (or not using?) and we'll be able to help you a bit more if you're still having trouble with this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号