Skip to content
Rohan Nagar edited this page Jan 30, 2018 · 7 revisions

When developing, you should be testing your changes and additions thoroughly. A rundown of the testing steps that you must follow is here.

1. Ensure Code is Covered by Unit Tests

The first thing you should do is make sure that unit tests exist for the code you wrote. Unit tests can be found in each module under .../src/test/java/com/sanction/thunder/.

Direct Links:

If you wrote new code, you must also write unit tests for it. Each class should have a corresponding JUnit test class. These test classes must be in the same package as the class they are testing. When writing test cases, make sure you test every public and package scoped method. For each of these methods, be sure the test cases cover all possible branches and statements. For example, consider the following code to test.

public class ExampleClass {
  public String exampleMethod(boolean sayMore) {
    String words = "Hello World!";
  
    if (sayMore) {
      words = words + " I think I hear Thunder in the distance!";
    } 

    return words;
  }
}

To fully test this method, you will need to write two unit tests.

public class ExampleClassTest {
  private final ExampleClass example = new ExampleClass();

  @Test
  public void testExampleMethodWithoutMore() {
    String expected = "Hello World!";
    String result = example.exampleMethod(false);

    assertEquals(expected, result);
  }

  @Test
  public void testExampleMethodWithMore() {
    String expected = "Hello World! I think I hear Thunder in the distance!";
    String result = example.exampleMethod(true);

    assertEquals(expected, result);
  }
}

If you modified existing code, you must ensure that your changes did not break the existing unit tests, and fix them if necessary. Also, you must determine if any modifications that you did have introduced the need for more unit tests or have rendered some unit tests unnecessary.

2. Run Unit Tests

When you have made sure all of your code is covered by unit tests, run the tests and ensure that they pass. This can be done easily via the command line by going through the build process. This is a good check anyway, as you should also make sure that your changes did not break the build.

To run the tests, navigate to the thunder directory on the command line and execute the following command.

$ mvn clean test

The source code will be compiled, and the tests will run. From here, you can see if all the tests pass or not. If you have failures, investigate the tests that failed and determine why. It may be that you wrote tests incorrectly, your code affected existing code and those test cases need to be modified, or your code has incorrectly modified the intended behavior. Determine which of these cases apply, and change your code accordingly.

3. Test the Endpoints

The last thing you should do before submitting a pull request is ensure that all of the available endpoints work correctly. These can be tested a few ways, depending on your preference. However, the easiest way is to run the Node.js test script.

First, get set up with Node.js. You will need to install the latest version of Node.js and NPM. If you're developing on macOS, installation is easy with Homebrew. Simply run the following command.

$ brew install node

Once Node and NPM are installed, we need to install the requirements for the test scripts. Run the following commands.

$ cd scripts/

$ npm install

$ cd ../

This goes into the scripts/ directory, installs the required packages that are defined in the package.json file, and then returns to the base directory.

Next, start Thunder by running the application jar with the test-config configuration file. From the base Thunder directory:

$ java -jar application/target/application-*.jar server config/test-config.yaml

Finally, to run the full integration test script, navigate back to the scripts/ directory and run the script using Node.

$ cd scripts/

$ node src/test-runner.js

There are many optional command line arguments for the testing script. When running the script from the command line, adding the -h option will display a help message with all optional arguments and their descriptions.

If you make changes to the public-facing API, you must update the test script!

After completing these three steps, you are ready to submit a pull request with your changes!