Ghidra: how to run single testcase?

Created on 28 May 2019  路  2Comments  路  Source: NationalSecurityAgency/ghidra

As far as I know, the test related commands in gradle scripts test all cases. How can I run a particular one?

Question

Most helpful comment

You could run the test in Eclipse, or via the command line. The test should pass in both, of course :crossed_fingers: .
To expand a bit more on running a single test via the cmd line:

If the test is in path "test" then the Gradle _test_ task should be used.
If it is in the path "test.slow" then use the _integrationTest_ task.
The sourceSets are defined in "./gradle/javaProject.gradle".

Some examples:

To run ghidra/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/string/StringTableSearchTest.java
gradle :Base:integrationTest --tests StringTableSearchTest

To run ghidra/Ghidra/Framework/Docking/src/test/java/ghidra/util/task/TaskLauncherTest.java
gradle :Docking:test --tests TaskLauncherTest.testLaunchFromSwing

The Gradle test filter (" --tests") supports pattern matching which you can read more about here.

Many times, your test does not rely on sleigh and help pages, so you could also exclude the following tasks to save time:

-x sleighCompile -x buildHelp

Also, many tests rely on a GUI component and will display windows that prevent you from using your computer while the test is running. Generally, these are in "test.slow" and part of the integrationTest task. In this case, it is useful to run Xvfb:

Xvfb :1 -screen 0 1024x768x8 -nolisten tcp
The " :1 " is your DISPLAY variable. Set your DISPLAY variable before running:
export DISPLAY=:1

All 2 comments

gradle test --tests ghidra.util.UnsignedDataUtilsTest.testIntLessThan

did a quick test, seems to work, taken from this SO

You could run the test in Eclipse, or via the command line. The test should pass in both, of course :crossed_fingers: .
To expand a bit more on running a single test via the cmd line:

If the test is in path "test" then the Gradle _test_ task should be used.
If it is in the path "test.slow" then use the _integrationTest_ task.
The sourceSets are defined in "./gradle/javaProject.gradle".

Some examples:

To run ghidra/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/string/StringTableSearchTest.java
gradle :Base:integrationTest --tests StringTableSearchTest

To run ghidra/Ghidra/Framework/Docking/src/test/java/ghidra/util/task/TaskLauncherTest.java
gradle :Docking:test --tests TaskLauncherTest.testLaunchFromSwing

The Gradle test filter (" --tests") supports pattern matching which you can read more about here.

Many times, your test does not rely on sleigh and help pages, so you could also exclude the following tasks to save time:

-x sleighCompile -x buildHelp

Also, many tests rely on a GUI component and will display windows that prevent you from using your computer while the test is running. Generally, these are in "test.slow" and part of the integrationTest task. In this case, it is useful to run Xvfb:

Xvfb :1 -screen 0 1024x768x8 -nolisten tcp
The " :1 " is your DISPLAY variable. Set your DISPLAY variable before running:
export DISPLAY=:1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tambry picture tambry  路  3Comments

ghost picture ghost  路  3Comments

huettenhain picture huettenhain  路  3Comments

marcushall42 picture marcushall42  路  3Comments

toor-de-force picture toor-de-force  路  3Comments