Unit testing of complex methods, what to test and what to accept?

Consider the function private void create (List<T> items). This code basically creates a tree that has a BFS jump list. Now suppose that this code returned root, and we could verify that it created the tree, but doing the crawls and checking the crawls is as expected. So far so good.

But:

  • Since this function is very complex, if we check / verify the need, that the calculations leftIndexand rightIndexexecuted carefully?

  • If so, how to check these internal details of the function?

In general, given a complex function, how to check internal calculations that contribute to the return value, but are hidden from using an API / function call?

+4
source share
1 answer

If you have a complex private method that you think will benefit from unit testing, the general approach is to make this method private, so you can reference it directly from unit test. In your case, you can use the traversal private-private methods or create a private-getter method for root.

, unit test , , . , , . , , . , API- .

unit test , , . , API .

+6

All Articles