jonathan
jonathan

Reputation: 21

How long should it take to write unit tests?

I'm a graduate trainee at a software company. They told me to learn unit testing and write unit tests for a project that has 3000 lines and 35 classes approximately in 3 weeks. I did read Art of Unit Testing in 2 days and getting used to unit tests took another day already. You think it is doable?

Upvotes: 2

Views: 3765

Answers (2)

k3b
k3b

Reputation: 14755

Wording:

Unittesting = Testing of one unit/class/feature independent of other unites/classes/features and independant of the whole solution/workflow/gui.

I think it is very hard and costly to write unittests () after the project has gone that far if the code was not optimized for testability.

i had the same problem and decided to write integration-tests instead that tests the whole aplication logic of a workflow where all non-gui-components worked together but without without the gui components. Luckily that was possible because there was good seperation between gui and business-logic.

I then started creating unittest-tests for modules i had to expand.

for both unittests and integrationtests i used junit and nunit.

Upvotes: 2

Reese Moore
Reese Moore

Reputation: 11650

Ignoring the fact that Unit Tests should be written before/during development, I would say that it is possible. It might be a right bitch, but it is definitely possible.

In this case the hardest part is going to be getting familiar with the code to understand what each method should be doing, rather than what the code says the code is doing. It makes no sense to test for bugs if you are writing the tests to pass with the current code. (This point goes back to the fact that the unit tests should be written before/during).

You are probably going to end up getting a good percentage for code coverage, but you will probably end up missing some code execution paths and edge cases that should/would have been addressed when the methods were written. In this case, when a bug or error comes up, make sure that some tests are written for that case so that once that bug is fixed it can never be reintroduced into the application.

I would say that it is fairly poor form on the part of the company to have written an entire project of that size and to have waited to dump writing the tests on to a graduate trainee after it has all been written, but that is just my opinion.

Upvotes: 6

Related Questions