Active Topics Memberlist Calendar Search Help | |
Register Login |
One Stop Testing Forum : Software Testing @ OneStopTesting : Test Cases @ OneStopTesting |
Topic: Interview Tip: Writing test cases |
|
Author | Message |
Pallavi
Newbie Joined: 23Feb2007 Online Status: Offline Posts: 1 |
Topic: Interview Tip: Writing test cases Posted: 23Feb2007 at 8:55am |
If during a dev interview, you're asked to write a set of test cases for some function you wrote, be sure to have test cases that reach every basic block. In other words, make sure your test cases at least hit every line of code you wrote. For example, if you need to write 'bool IsEven(int x)' which returns true iff x is even, and you write something like this: 1: bool IsEven(int x) It's bad enough that you have a bug in line 6. But then if the followup interview question is "Write some test cases for your function", and your test cases are: You're doubley doomed. Other quick rules for test cases. At least ensure your test cases:
I think some good test cases for IsEven above would be: assert(IsEven(0) == true) // 0 is a common corner case Bonus points: more complex test cases. If the baseline tests are all the interviewer is interested in, then you're good with the above. If that satisfies the interview, great! Move on to the next question. (related Interview tip: don't wast the interviewer's time) But if you're asked something like "how else could you test this to
be super confident that it's really correct in all case", you could
have some fun with more complex tests that use properties / identities
of your function. For example, you know that: Thus you could write a test that iterates through all possible inputs and verifies it against all outputs. Toss in that your function is stateless and now your talking about empirically provably correctness. That's sure to get some bonus points in an interview. :)
Post Resume: Click here to Upload your Resume & Apply for Jobs |
|
IP Logged | |
somanianand
Newbie Joined: 07May2007 Location: India Online Status: Offline Posts: 1 |
Posted: 07May2007 at 11:14pm |
Testcase should be :
1. only single purpose.
2. not more complex. easy steps.
3. Starting & end point should be same.
4. Self understanded.
5. with all commits
6. variable name should understandable like "int abc" - > int i_abc
7. testcase should clear & reusable.
8. testcasse should maintainable.
|
|
IP Logged | |
Forum Jump |
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
© Vyom Technosoft Pvt. Ltd. All Rights Reserved.