-
Notifications
You must be signed in to change notification settings - Fork 604
Unit Tests
Normally, code should be tested (explicitly or implicitly) by FAT tests which run test applications that access APIs exposed by configured features. This is partly because unit tests are only run during compile/build phase, and when the full test suites are run, the compile/build phase is generally only run on one or a few machines, rather than all of them (FAT tests run on all).
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.
-
Add to
.classpath
:<classpathentry kind="src" output="bin_test" path="test"/>
-
Add to
bnd.bnd
:-testpath: \ ../build.sharedResources/lib/junit/old/junit.jar;version=file
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 tocom.ibm.ws.whatever/build/libs/reports/jacoco/test/html/jacoco-sessions.html
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
.