views:

517

answers:

2

In an interview, whether for developer positions or white-box qa positions, you are ofter asked to:

  • create test cases for a piece of code / API
  • categorize each test i.e. functional, stress, load, performance, security etc.
  • prioritize (assuming low / medium / high priorities)

I want to gather up ideas for such test cases. We can assume a normal application, so if the question is for a shuttle controller, the priority for stress testing would be considerably higher. You can start from a C++ piece of code, like:

char* reverseString(char* myString) { //some implementation }

or some modern code (C#, Java)

string Reverse() { //some implementation }

For black-box testing, a similar question is here.

Here are some of my ideas:

  • [functional, high] if testing strings or some other form of a collection, see if the code works for a collection with even number of elements, odd number, special elements within (spaces for strings), single element and a combination of these
  • [functional, high] test to fail - empty string, NULL pointer, very large string, non null terminated string
  • [functional, high] check the documentation
  • [functional, high] for the C version, using char means this will work only on ANSII strings - use wchar_t instead.


  • [stress, low] pass in a pointer to a protected memory area
  • [stress, low] big endian vs little endian


  • [security, high] for C++, check the code for buffer overruns


  • [performance, medium] check that the algorithm's complexity is low
  • [performance, high] if there are some "service level agreements" (e.g. the reverse function should return the value in maximum 5 seconds), test them with a high priority
  • [performance, low] check for memory leaks by running the code many times and measuring the memory used each time (this is also relevant to C# where we can have event leaks, static data leaks, resource leaks etc. but the testing methodology is a little different because the GC is non-deterministic)


  • [usability, low] if stress testing reveals limits, make sure these limits are enforced and proper errors are given (e.g. if you cannot reverse a string larger than 2 Gb of data, the user should be informed)
  • [usability, high] the code should be consistent with the rest of the API, for example when handling errors (exceptions, error codes)


  • [localization, high] - random inputs of UTF-8 and ANSII strings
  • [localization, low] - should work on a machine with the OS in another language


  • [regression , low] - record some data (e.g. time to reverse some words) as baseline and check them every time some changes are made


  • [manageability, medium] - the code is commented, well structured and conforms to the chosen coding standard

Feel free to comment on any and add your own!

A: 

Seems like this should move to a community wiki?

PSU_Kardi
+1  A: 

Related video How To Design A Good API and Why it Matters By Joshua Bloch.

OscarRyz