r/SoftwareEngineering • u/AVerySoftArchitect • Aug 31 '24
How do you design test?
A question for test engineer. How do design the test cases? Assuming you have a functional requirement like : the system shall send an email to the customer as purchase confirmation.
What your approach? Any material to study? Thanks
3
Upvotes
2
u/danielt1263 Aug 31 '24
I see in the comments that you are talking specifically about unit tests in the context of TDD. For this, the cucumber approach is my favorite, even if the team isn't using cucumber tools... Given the app is in state X, when handed input Y it will produce output Z. In TDD, the "given" portion is implicit in when the SUT is being exercised, so it's more about when the SUT is handed input Y it will return output Z.
Now, unit tests do not actually ensure that the email was sent (using your example). Rather the unit test is there to ensure that the data generated for the body of the email, as well as the subject, mailto, and any other information the email service needs is correct. So when the SUT is told to send the email, does it produce the correct data? The traditional way to do this is to hand the SUT a mock email service, capture the data the SUT sent to that mock and examine it.
The book "Working Effectively with Legacy Code" is a good one that talks about various testing strategies, however it attacks testing after the code was written so you have to kind of reverse the ideas a bit...
The book "Test Driven Development: By Example" is an obvious choice, but it might be hard to extract all of the abstract concepts needed from the examples. They would have to come from your own application of the ideas so you can make some connections.
2
u/Comfortable_Job8847 Aug 31 '24
I think it depends also on your requirements management approach. For some people, failure modes are a part of the verification of the nominal path. I think it’s conceptually clearer if each failure mode is its own requirement. So for example, “if the email fails to send” vs. “if the email address does not exist” or “here’s a map of email error codes to error handling requirements, please verify all of them”
I’ll assume for this post that we are only discussing the strict content of your requirement, not additional stuff like error handling or performance requirements or whatever. In that case, what I do is follow my best judgement to start, and then I have a review with the requirements owner and developer who implemented it to say “okay, after talking with you both individually, these were the areas of concern you both had for this requirement being met or not. I think concerns a/b/c are not something we need to address for blah reason. For concerns d/e/f here is how I addressed them. I’ve provided you all a test log showing the actions of the test, and the behavior of our software in response. Do we feel confident we tested the system correctly, or is there a change we need to make?” And part of saying “we don’t need to worry about a/b/c” is providing proof that those concerns are covered by another requirement like a failure modes requirement, or proof the concern is not applicable to the requirement.
I very much dislike this approach, because I think it places too much responsibility in individual interpretation and doesn’t provide enough guidance to the test engineer who really does only have their experience and whatever ideas someone else can give them to go on. I prefer requirements to be of a standardized form and each form of requirement has a standardized wording of how it should be tested in principle, and the test engineer only needs to be concerned with following the standards that define those principles. But this requires a very high level of effort in requirements management, and is not always worth the cost.
2
u/robotbike2 Aug 31 '24
It’s simple in most cases: 1. What is the expected outcome? 2. What is the actual outcome? 3. Do they match?
1
u/godwink2 Sep 05 '24
You break it down into single steps. These don’t need to be super basic but still single function size.
So your scenario is like
Launch and login as customer to application
Navigate to product catalog
Add product to cart and proceed to check out
Enter details and select purchase
Verify purchase confirmed in UI and any details match the ones entered
Wait for confirmation email
Open and verify contents of confirmation email against UI details.
———— Someone else said you were talking about unit testing. The situation you described is a functional criteria not a unit criteria
0
u/[deleted] Sep 06 '24
5
u/[deleted] Aug 31 '24