Tests separation

If we follow some kind of convention, it is fairly easy to separate tests in Gradle. We can have our tests in different directories and distinct packages or, for example, with different file suffixes. In this case, we choose the latter. All our specification classes are named with the Spec suffix (that is, TicTacToeSpec). We can make a rule that all integration tests have the Integ suffix.

With that in mind, let us modify our build.gradle file.

First, we'll tell Gradle that only classes ending with Spec should be used by the test task:

test { 
    include '**/*Spec.class' 
} 

Next, we can create a new task, testInteg:

task testInteg(type: Test) { 
    include '**/*Integ.class' 
} 

With those two additions to build.gradle, we continue ...

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.