In NUnit, how can I explicitly run a test

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.

+5
source share
5 answers

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 ();

+18
source

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() , :)

+3
+1

Assert.Fail(): http://www.nunit.org/index.php?p=utilityAsserts&r=2.2.7

, , Assert.NoThrow - , , .

+1
[Test()]
public void Test( )
{
    GetNumber();
}

. , , .

0

All Articles