Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an automated way to make sure that all parts of code is unit tested?

I have written JUnit tests for my class, and would like it to tell me if there is any part of my code that is not unit tested. Is there a way to do this?

like image 347
chustar Avatar asked Mar 30 '10 02:03

chustar


People also ask

Can unit testing be automated?

Unit testing can be done manually but is usually automated. Unit testing is a part of the test-driven development (TDD) methodology that requires developers to first write failing unit tests. Then they write code in order to change the application until the test passes.

Is unit testing always automated?

Is unit testing manual or automated? Unit tests are usually automated because it's too costly, time-consuming and difficult to isolate units manually. The issue is that unit testing is a part of the web development/app development process.

Which method test all the parts of the program?

UNIT TESTING is defined as a type of software testing where individual units or components of a software are tested.

Can code coverage be automated?

Code coverage on automated or manual tests is more like a nice to have activity. We can live with or without it. It is useful for big matured products where there are automation test suites. You can also do them against your tests code in order to optimize it.


2 Answers

Yes, coverage tools like cobertura or emma.

They create reports that show every line in the source code and whether it was executed or not (and aggregated statistics as well).

Of course, they can only show you if the code was run. There is no way to tell if the unit test contained assertions to confirm that the result was correct.

like image 123
Thilo Avatar answered Oct 02 '22 05:10

Thilo


You need some code coverage tools. See here (http://java-source.net/open-source/code-coverage) for some

If you look at the first one I think it does what you need

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage. Features of Cobertura:

  • Can be executed from ant or from the command line.
like image 38
Preet Sangha Avatar answered Oct 02 '22 06:10

Preet Sangha