Betlista
Betlista

Reputation: 10547

Proper unit testing

I'm not quite sure if this question fits SO standards, but...

I'm experienced in using JUnit for testing of Java application together with mocking and so on... But there is one thing that I'm concerted about - How to be sure that each class and each method is really tested?

I found something that looks similar to what I want to achieve - GrandTestAuto (inspiration came from testing tools page), can you recommend another (better) approach?

I have to test it (GTA) more, I'm interested in Spring, Mocking, Maven to work together, but I'm sceptical a little bit.

I'm using coverage reports also (JCoverage, JaCoCo), but this is not accurate, because when you test method a() that calls b() both are covered, but as a developer I want to write tests for b().

edit:
I found JUCA report, I need to test this also.

edit2:
Ok, idea about a() calls b() has to be more.

See the ecample

void a() {
    b( "test" );
}

void b( String s ) {
    Assert.notNull( s );
    // ...
}

when a() is covered, b() is covered also, but the case that s is null is not and it often happens, because b() is not tested at all.

Upvotes: 1

Views: 70

Answers (1)

ethanfar
ethanfar

Reputation: 3778

I think that code coverage is a fairly good way of knowing what is completely untested, but it's not a lot more than that.

What I suggest is two things:

  • Test Review - Same as code reviews, but for the code of the test. You wouldn't believe how effective that is
  • Mutation Testing - Automatic tools that change the production code in runtime and check that the tests covering it are failing. I'm working with PIT (http://pitest.org/), and highly recommend it

Upvotes: 3

Related Questions