In the test below, if it enters the catch block I want to indicate that the test has passed. If the catch block is bypassed I want the test to fail.
Is there a way to do this, or am I missing the point with how tests should be structured?
[TestMethod]
public void CommandExecutionWillThrowExceptionIfUserDoesNotHaveEnoughEminence()
{
IUserCommand cmd = CreateDummyCommand("TEST", 10, 10);
IUser user = new User("chris", 40);
try
{
cmd.Execute(user);
}
catch(UserCannotExecuteCommandException e)
{
//Test Passed
}
// Test Failed
}
I tend to use this pattern when I have a similar situation:
// ...
catch (UserCannotExecuteCommandException e)
{
return; // Test Passed
}
Assert.Fail(); // Test Failed -- expected exception not thrown
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With