Skip to content

Unit Tests

kgibm edited this page May 15, 2018 · 10 revisions

Normally, code should be tested (explicitly or implicitly) by FAT tests which run test applications that access APIs exposed by configured features.

However, in some cases, it may be useful to write unit tests outside of the FAT infrastructure.

Unit tests are housed within the test subfolder of a project.

Adding Unit Tests to a Project that doesn't have them

  1. Add to .classpath:

    <classpathentry kind="src" output="bin_test" path="test"/>
    
  2. Add to bnd.bnd:

    -testpath: \
      ../build.sharedResources/lib/junit/old/junit.jar;version=file
    

Running Unit Tests

Different ways to run unit tests:

  • ./gradlew com.ibm.ws.whatever:test
  • ./gradlew com.ibm.ws.whatever:build
  • In Eclipse, right-click on the test directory and select Run As > JUnit Test
  • If you want a code coverage report to be generated (in addition to running the unit tests), you can do ./gradlew com.ibm.ws.whatever:jacocoTestReport - the report is output to com.ibm.ws.whatever/build/libs/reports/jacoco/test/html/jacoco-sessions.html

Adding test-only dependencies

If you need to add extra dependencies to your unit test classpath, do so via -testpath in bnd.bnd instead of -buildpath. Note that -buildpath gets inherited into the -testpath.

Clone this wiki locally