Test unit and helper/demonstrators

Viewed 23

I have been developing unit test in Javafor some years know but I am struggling with a new technical need. My question is more related to test organisation and classification.

I have regular unit test on one side for business logic. So far so good. On the other side, some of my developers are using test unit to demonstrate some use of features. It looks like more as component test actually. It generally illustrates how libs should work together or how a developer should start using a piece of code. It does not really improve code coverage but it is a good source of knowledge for code templates. There is no need for those tests to be launched at every build.

I wonder how you classify such tests in a project ? First to find them easily for developers. Secondly to avoid playing them all the time.

Woul'd you use class naming ? Create another test folder named helpers ?

1 Answers

If you are using JUnit 5 you can utilize Tagging and Filtering e.g.

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("fast")
@Tag("model")
class TaggingDemo {

    @Test
    @Tag("taxes")
    void testingTaxCalculation() {
    }

}

and then if you run your tests e.g. with gradle you can filter it e.g.

test {
    useJUnitPlatform{
        excludeTags 'taxes'
    }
}

See here

Related