For example, the code below
[Test()] public void Test( ) { try{ GetNumber( ); } catch( Exception ex ){ /* fail here */ } ... }
I want to skip my test when the GetNumber method throws an exception.
Please inform.
Many thanks.
You do not need to wrap GetNumber () inside try / catch. If GetNumber () throws, your test will fail.
If you need to execute it explicitly, use Assert.Fail ();
If it GetNumber()returns a value, you should not do what you are trying to do. Instead, you must confirm the return value. Don't bother checking for exceptions unless you expect this to happen. The NUnit framework will take care of this and will not test your test.
GetNumber()
GetNumber() , :
. , , , , . GetNumber() , :)
, , ExpectedException. , .
Assert.Fail(): http://www.nunit.org/index.php?p=utilityAsserts&r=2.2.7
Assert.Fail()
, , Assert.NoThrow - , , .
[Test()] public void Test( ) { GetNumber(); }
. , , .