Skip to content

Instantly share code, notes, and snippets.

@mishin
Created October 29, 2021 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishin/b927d5f85c4d49c7e610148fb02f9094 to your computer and use it in GitHub Desktop.
Save mishin/b927d5f85c4d49c7e610148fb02f9094 to your computer and use it in GitHub Desktop.
Java Test naming convention.

Java Test Naming Convention

This is intended as a quick Java test naming convention.

Table of Content

Test method naming
References

Test method naming

Method name template.

<unit-of-work>[WHEN<state-under-test>]THEN<expected-behaviour>

Javadoc template.

/**
 * <unit-of-work-description>
 *
 * Given: <preconditions>
 * When: <state-under-test>
 * Then: <expected-behaviour>
 *
 * @author <author>
 */

Example:

/**
 * Always return true method test.
 *
 * Given: Library is instantiated
 * When: Simple call
 * Then: Success
 *
 * @author Giovanni Farfán B.
 */
@Test
public void alwaysReturnTrueWHENsimplecallTHENsuccess() {
  Library lib = new Library();
  assertTrue("should return 'true'", lib.alwaysReturnTrue());
}

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment