What methods are absolutely necessary?

My team has been working on developing an application that has been working for several years now, but no unit test has ever been coded. Now that we want to start doing this, we understand that we will not be able to go through all the existing methods to test them, because it will take many years of work.

The question is, how do you decide which method is absolutely necessary for unit testing and which is not?

Do you prefer a unit test method that is often called, or a method that changes frequently? I've read that Unit Testing is pretty ineffective in DAO classes. Should I hold back tests to methods containing logic?

Most important: Will the tests be enforced if only part of the application is tested on the device?

+3


source to share


2 answers


how can you decide which method is absolutely necessary for unit testing and which is not?

This is a tricky question to answer without knowing about your codebase and its history and future. But in general, writing tests for parts of the code that are hard to understand, will be changed in the near future, or are known to have bugs. When testing outdated applications, the best hit for your dollar is having tests that make it easier to use the program in the future, fix bugs and revert old bugs.

Do you prefer to unit test a frequently called method or a frequently modified method?

As stated above, it depends. Is a method that is often called trivial? Is it easy to understand? I am probably leaning towards "changing frequently" to facilitate future development. But ideally, both should be tested.

I read that unit testing is pretty inefficient for DAO classes.



I don't know where you are reading this. Unit testing can be very effective with DAO if you are using mock objects.

Will the tests be enforced in any way useful if only part of the application is being tested on the device?

Any tests are helpful. A program that only covers 10% of tests is better than a program with 0% coverage. Especially if 10% is the most important or difficult part of the program.

If you haven't read it yet, I highly recommend Michael Feather to work effectively with Legacy Code, where "legacy code" means code that has no tests.

+2


source


Some people create unit tests for getters and setters and insist on 100% code coverage.

Practical people will test those methods that need testing. This means that it will depend on your intelligence and understanding of what constitutes the method that needs testing.



Some people , however, believe that the minimum unit size is a class and that tests should be created to test a class (and sometimes its associated classes).

In short, forget about any dogmatic principle about unit testing, the quality of your code is important. Like agile development, it helps you achieve this important goal. So if you feel like your DAOs won't be useful for testing, then don't worry - take the time you would have spent doing something more productive.

0


source







All Articles