As per CemKaner
Writing a test case is complex art
A test case is a question which we ask of a program and when executed should return some information.
And what would that information be? Well it actually depends on the type of question we ask and the information we are seeking out of that program.
It could be :
- Seek defects - We look for defects in all interesting parts of product, looking for failures in the product that could expose defects.
- Maximize bug count - Focus could be on testing high risk areas and finding as many defects as we can instead of trying to achieve coverage.
- Block premature product release- Focus only on finding showstopper bugs.
- Help managers make ship/no ship decision-managers may want to know the coverage of testing.
- Assess conformance to specifications - Any claim made in the specifications is checked.
- Verify correctness of the product- It's impossible to test the product exhaustively, you can prove that the product is not correct by trying to achieve coverage while designing test cases but there will always be some cases which you didn't test and the product might fail in those conditions.To verify the product is correct best you can do is estimation of the probability of errors.
And how do you design it?
People tend to create tests based on testing styles.Within black box testing there are 11 test styles:
- Function testing
- Domain testing
- Specification based testing
- Risk based testing
- Stress testing
- Regression testing
- User testing
- Scenario testing
- State model testing
- High volume automated tests
So, for a scenario where aim is to find defects that the rest of the development group finds worth reporting, then one test case will be better than the other if
- More credible and real representative of the events more likely to be encountered by customer
- More useful for troubleshooting and thus easier to replicate
- More likely to help the tester, developer develop some insight into the problem
- Appropriately complex- Complexity in a test case is less desirable when a new feature has been launched as the build isn't yet stable.Running a complex case is more likely to fail in the first run thus preventing you from running the other cases within the suite of tests thereby preventing you from receiving any information about the product which you could have obtained otherwise.Thus its advisable to run simpler test cases at the beginning and then move onto complex ones as the build becomes more and more stable.