Hard assertions:
When a hard assertion fails, it throws out an exception immediately and the code after the assertion shouldn't be excuted,the test case is failed.
Soft assertions:
When a soft assertion fails, it does not throw out an exception, and would continue with the next steps after the soft assertion.
When to use hard assertions?
When a step in the test is very important, if this step fails, the following steps shouldn't go on, you may put a particular hard assertion to verify this step, if the hard assertion fails, the testing stops and the test case is failed. For example, when you test "login in a page and then do some operations after login", if login fails, the next operations can't be done, in that situation, you can put a hard assertion to verify the login operation. If the assert fails, testing excution stops, test case is failed.
When to use soft assertions?
In some situations, even the current test step fails, you may still want to do the next steps, then you can put a soft assert to verify the current step. If it fails, it only gets a fail log but the testing excution keeps going on. The next test steps should be run. For example, you want to print 4 items, if one of them fails, you still hope to print the next one. In that situation, you may put soft assertion to verify the test step "print one item", even it fails, the testing excution will goes on to print next items, and the test case will be passed.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment