JUnit Plugin - Macros


# EXECUTE_JUNIT_TEST {displayName} FROM {qualifiedClass} IN {bundlePath}

What ?

This macro will execute a JUnit test and verify that the result is a success.

Underlying instructions :

LOAD {bundlePath} AS junit5{%%r1}.file
CONVERT junit5{%%r1}.file TO script.java(compile) AS junit5{%%r1}.bundle
CONVERT junit5{%%r1}.bundle TO script.junit5(structured) AS junit5{%%r1}.script
EXECUTE execute WITH junit5{%%r1}.script AS junit5{%%1}.result USING $(qualifiedClassName:{qualifiedClass},displayName:{displayName})
ASSERT junit5{%%1}.result IS success

> Input :

  • {qualifiedClass} : The qualified name of the class containing the test to execute.

  • {displayName} : The name of the test to execute.

    • For a JUnit4 test, specify the name of the method being tested (without parentheses).
    • For a JUnit5 test, you can also specify the name of the method being tested (with parentheses), but you have to use the display name of the method if you tagged it with ‘@DisplayName’. Make sure the display name of the test is unique in the class being tested.
  • {bundlePath} : The path to the java code bundle, including resources and compiled java classes.

Example :

JUnit4 : # EXECUTE_JUNIT_TEST testSelenium2JUnit4 FROM org.squashtest.Selenium2JUnit4 IN selenium
JUnit5 : # EXECUTE_JUNIT_TEST testSelenium2JUnit5() FROM org.squashtest.Selenium2JUnit5 IN selenium
JUnit5 (DisplayName) : # EXECUTE_JUNIT_TEST Test_Selenium_2_JUnit_5 FROM org.squashtest.Selenium2JUnit5 IN selenium

File to process :

../../_images/junit-macros-execute-1-test-class.png

The folder containing the resources to process :

../../_images/junit-macros-execute-1-tree.png

SKF script :

../../_images/junit-macros-execute-1-script.png


# EXECUTE_JUNIT_TEST {displayName} FROM {qualifiedClass} IN {bundlePath} WITH COMPILE OPTIONS {options}

What ?

This macro will execute a JUnit test, with compile options, and verify that the result is a success.

Underlying instructions :

LOAD {bundlePath} AS junit5{%%r1}.file
CONVERT junit5{%%r1}.file TO script.java(compile) USING {options} AS junit5{%%r1}.bundle
CONVERT junit5{%%r1}.bundle TO script.junit5(structured) AS junit5{%%r1}.script
EXECUTE execute WITH junit5{%%r1}.script AS junit5{%%1}.result USING $(qualifiedClassName:{qualifiedClass},displayName:{displayName})
ASSERT junit5{%%1}.result IS success

> Input :

  • {qualifiedClass} : The qualified name of the class containing the test to execute.

  • {displayName} : The name of the test to execute.

    • For a JUnit4 test, specify the name of the method being tested (without parentheses).
    • For a JUnit5 test, you can also specify the name of the method being tested (with parentheses), but you have to use the display name of the method if you tagged it with ‘@DisplayName’. Make sure the diplay name of the test is unique in the class being tested.
  • {bundlePath} : The path to the java code bundle, including resources and compiled java classes.

  • {options} : The name of the configuration resource. It represents a configuration file containing java compilation options (possible options are those of the Java compiler present on the machine). In this file options can be written :

    • In line separated with a space character
    • One option per line
    • A mix of both

Example :

JUnit4 : # EXECUTE_JUNIT_TEST testSelenium2JUnit4 FROM org.squashtest.Selenium2JUnit4 IN selenium WITH COMPILE OPTIONS compile.options.file
JUnit5 : # EXECUTE_JUNIT_TEST testSelenium2JUnit5() FROM org.squashtest.Selenium2JUnit5 IN selenium WITH COMPILE OPTIONS compile.options.file
JUnit5 (DisplayName) : # EXECUTE_JUNIT_TEST Test_Selenium_2_JUnit_5 FROM org.squashtest.Selenium2JUnit5 IN selenium WITH COMPILE OPTIONS compile.options.file

First file to process :

../../_images/junit-macros-execute-1-test-class.png

Second file to process :

../../_images/junit-macros-execute-2-options.png

The folder containing the resources to process :

../../_images/junit-macros-execute-2-tree.png

SKF script :

../../_images/junit-macros-execute-2-script.png