Mike B.
Mike B.

Reputation: 180

Writing unit tests for large data structures

Assume you have a method Tree supersizeMe(Tree input) . Both input and the return value are recursive data structures, and the method returns a structure with a size factor of about 500. Hence if input is the smallest element possible, the return value of the function contains about 500 elements.

This is the short description of a situation I currently have, and I am supposed to write a unit test. Of course, having a minimal output size of ~500 elements, I can't really base my tests on assert-statements. So here is my question:

What is a good idea to test such a method?

PS: I can verify the output manually by sending it through an external program; Such functionality is included in my API, but using those classes conflicts with the idea of a unit-test, doesn't it?

Edit: The API is developed in java, and I use jUnit4 for tests.

Upvotes: 2

Views: 1628

Answers (1)

Michael Borgwardt
Michael Borgwardt

Reputation: 346327

but using those classes conflicts with the idea of a unit-test, doesn't it?

The idea of a unit test is that it tests single units of code in isolation. I don't see how using complex third-party code to verify correctness would run against that.

The real question is whether the transformation is in itself a simple enough operation that a failing test would give you a good idea where the problem is. If not, you may want to break it down into smaller operations that can be tested independently.

There may be TDD purists that claim any test that is not immediately and completely understandable and tells you exactly in which line of code the problem is is not a true unit test, and that using a third-party API is not acceptable, but they can go suck on their dogma while you enjoy your working, tested code.

Upvotes: 5

Related Questions