Skip to content

JUnit Testing

HowardYaw edited this page Nov 5, 2020 · 4 revisions

Guide on JUnit Test

Create New Test

Test Directory: src/test/
Integration Test is used and expected to be create in each feature branch

  1. Create a file with the controller naming if the test file is not exists
    (Eg: AccountResourceIT)
  2. Create Test with consistent and clear naming [ activity_{condition:opt}_{expected:opt} ]
    (Eg: createUser_WithEmailExists_ShouldThrow400)
  3. Execute the test on local and make sure it success before commit and push

Execute Test

To run all tests on your local machine:

mvn clean
mvn clean verify

Setup Configuration For Build and Run (Optional)

This is to make the testing of application done with one click in Intellij

Create JUnit Configuration

In Configuration Tab:

  • Test kind:
    • All in package
  • Package:
    • com.thirdcc.webapp
  • Search for tests:
    • In whole project
  • Before Launch:
    • Add RunMavenGoal with command clean before build
  • Shorten Command Line:
    • Select classpath file

In Code Coverage tab:

  • Add packages and classes to record coverage:
    • web
    • service
    • repository

Run the Application

  • Select the configuration
  • Click on Run with Coverage button (Third button usually)

Clone this wiki locally