SeattleOrBayArea
SeattleOrBayArea

Reputation: 3118

Testing a function: what more should be tested?

I am writing a function that takes three integer inputs and based on a relation between the three, it returns a value or error. To test this, I have written some test cases which include testing illegal values, boundary conditions for integers including overflows and some positive tests too. I am wondering what else should be tested for this simple function?

Can testing on different platforms make sense as a test case for such a small function? Also, testing execution times is another thing that I wanted to add as a test case. Can doing static and dynamic analysis be a part of the test cases? Anything else that should be tested?

int foo(int a, int b, int c) {
   return a value based on a, b, and c. 
}

Upvotes: 0

Views: 226

Answers (2)

Zane
Zane

Reputation: 926

The way you ask your question it seems you are doing a black box test, i.e. you only know about the relation between input and output, and not about the implementation. In that case your test case should depend on what you know about the relation, and I think you have tested these things (you didn't give us details on the relation).

From that it doesn't look as if you need to test for platform independence, but if you have an automated test suite, it is for sure not a bad idea to test it on different platforms.

Now if you have the code available, you could go for white box tests. Typically you would do this by looking at your code structure first, i.e. you could try to have 100% branching coverage, i.e. every branch in your code is at least run once during the tests. In that way, static and dynamic analysis could help you to find different coverage measures.

I wouldn't go for a platform independency test if there is no platform dependent code in your function.

Upvotes: 2

Aniket Inge
Aniket Inge

Reputation: 25695

sizeof(int) must be tested for the particular compiler. Although this seems trivial and C standard specifies the size for an int, its always better to know if the compiler being used is a 16 bit standard-noncomformant compiler. Just another test case.

Upvotes: 0

Related Questions