Unit testing for private methods

I'm currently trying to create some classes to perform some Fourier transforms. I am trying to do this by first creating some unit tests and then creating basic functions.

The problem with this is that well, I can write one test to see if the algorithm works, and I know the expected result. Then I begin to build a large algorithm, and if it works, my unit tests will pass.

My problem here is not TDD. Because usually you create tests that test the very basic function of a class. Now my class basically runs one big algorithm, and I cannot test the smaller parts of the algorithm, since they are not publicly available (I was always told that you would never want to test private methods).

How do you deal with this?

+5
source share
4 answers

I see two possible ways:

  • If possible, move the implementation of the algorithm to another class and divide it into methods. Testing methods after.
  • Just write a bunch of tests that cover possible common cases, edge cases, and errors.
+3
source

" ?" .

, , , , , .

, , , .

+1

, ( ), , , ? , TDD, - , , . - , ? ?

, , , , , , FFT ?

+1

, , , .

, . , , API.

0

All Articles