In this section:
Use the -help
command line switch:
jtestcli.exe -help |
Typically, if you connect through a proxy server, you need to configure the connection by passing protocol-specific system properties to the JVM – using the -D
command line option.
To work with Jtest, ensure that the system properties for the HTTPS protocol are configured. At a minimum, you must configure https.proxySet=true
, https.proxyHost=[hostname]
, and https.proxyPort=[port number]
. If your proxy server requires authentication, you can configure your credentials with the https.proxyUser
and https.proxyPassword
properties.
Your command line may resemble the following:
java -Dhttps.proxySet=true -Dhttps.proxyHost=myserver.example.com -Dhttps.proxyPort=8080 -Dhttps.proxyUser=user1 -Dhttps.proxyPassword=MyPassword |
https.nonProxyHosts
property to specify hosts where connection via proxy is not required.If you use Jtest on a desktop with Eclipse or IntelliJ IDEA, Jtest automatically detects and uses the proxy settings specified in Eclipse or IntelliJ IDEA. No additional configuration is required.
If the following dialog appears: "java" cannot be opened because the developer cannot be verified, follow the procedure below:
See also https://support.apple.com/en-us/HT202491.
Changes in the network environment may affect the interface that is used to compute your machine ID and result in machine ID instability. You can use the PARASOFT_SUPPORT_NET_INTERFACES environment variable to specify a stable interface and prevent the machine ID from floating.
Set the variable value to a stable Ethernet network interface. Do not use virtual, temporary or loopback interfaces.
- On Windows: Set the value to the MAC address of your network card. You can use the ipconfig -all
command to obtain the address. For example:
SET PARASOFT_SUPPORT_NET_INTERFACES=00-10-D9-27-AC-85 |
- On Linux: Set the value to one of the network interfaces from the "inet" or "inet6" family. You can use the ifconfig
command to obtain the list of available interfaces. For example:
export PARASOFT_SUPPORT_NET_INTERFACES=eth1 |
If the problem persists, you can obtain diagnostic information by setting up the environment variable PARASOFT_DEBUG_NET_INTERFACES and setting its value to true. This will print to the standard output the checking procedure that can be shared with technical support, as well as the interface that is used to compute your machine ID. The interface will be marked with the [SELECTED] prefix.
If you are a Mac OS user, you will encounter an issue with executing Jtest since it does not have the application format typical for Mac OS and it is downloaded outside the App Store. Therefore, both jtestcli and the included JRE will be placed in quarantine.
This is a common issue for all the non-App Store applications. You can manually allow each executable to open in the Mac OS Privacy & Security system settings (see https://support.apple.com/en-us/HT202491). To easily remove the quarantine attribute from these files automatically, run the jtest_installation_folder/bin/remove_quarantine_flag.sh
script.
The new version of Jtest may require more memory to run static analysis. You can increase memory allocation by configuring the -Xmx option in the [INSTALL_DIR]/etc/jtestcli.jvm configuration file.
If Jtest reports compilation problems related to importing dependencies in the Maven test scope, try running the jtest:jtest
goal with the mvn test
command:
mvn test jtest:jtest |
jtest:coverage
goal (Maven) or jtest-coverage
task (Gradle) fail the build?The Jtest coverage
goal/task was dropped with release 10.2.2 (plugin version 1.2.4) and is no longer available (see Migration From 10.x to 10.2.2 or later). Executing this goal fails the build with the following messages:
[ERROR] Could not find goal 'coverage' in plugin com.parasoft.jtest:jtest-maven-plugin
. (Maven)
Task 'jtest-coverage' not found (Gradle)
A Gradle build may fail when you perform test impact analysis with Jtest on multi-module projects if a submodule does not contain tests that are identified as affected tests during test impact analysis. To prevent a Gradle build from failing when no tests are found, configure the following option:setFailOnNoMatchingTests(false)
To enable collecting coverage, Jtest automatically configures the JVM arguments for the Jtest coverage agent. Overriding these arguments prevents Jtest from collecting coverage data. If your Gradle build script modifies JVM arguments, ensure they are added (+=) to other JVM arguments to prevent overriding:
] |
] |
To ensure that files that include BOM are properly processed and tested, you need to configure Jtest to remove BOM when the file is parsed. Add one of the following settings to the jtest.properties
configuration file:
jtest.parser.bom=remove
- removes BOM and leaves the original file encoding unchanged.jtest.parser.bom=recognize
- removes BOM and overrides the original fine encoding with the encoding defined by BOMBy default, Jtest does not differentiate between tests that always fail when run on the same code and tests that can either pass or fail (flaky tests). You can configure Jtest to recognize flaky tests by enabling the deprecated XML processing mechanism to be used for test execution. Add the following option in the jtestcli.properties
configuration file:
jtest.unittest.xml.results.processing.enabled=
true
Note that enabling the deprecated XML processing mechanism may slow down test execution.
When running PowerMock tests with mockito-inline on the classpath before powermock, you might encounter test failures with the following exception:
NotAMockException: Argument should be a mock, but is: class java.lang.Class |
This is caused by an issue with how PowerMock interacts with the mockito-inline mock maker (see PowerMock issue for details).
There are several possible solutions depending on your requirements:
There are some limitations concerning the classes and methods which can be mocked. For details, see Mockito static and constructor mocking limitations.
The following PowerMock calls which cause an issue can be easily modified:
For example:
PowerMockito.when(MyClass.staticCall(any())).thenReturn("value"); PowerMockito.when(MyClass.staticCall(any())).thenReturn("value1", "value2"); PowerMockito.doReturn("value").when(MyClass.class); MyClass.staticCall(any()); PowerMockito.doNothing().when(MyClass.class, "staticCall", any()); |
Updated code:
PowerMockito.when(MyClass.staticCall(any())).thenAnswer(invocation -> "value"); PowerMockito.when(MyClass.staticCall(any())).thenAnswer(invocation -> "value1").thenAnswer(invocation -> "value2"); PowerMockito.doAnswer(invocation -> "value").when(MyClass.class); MyClass.staticCall(any()); PowerMockito.doAnswer(invocation -> null).when(MyClass.class, "staticCall", any()); |
When calling verifyStatic() or verifyPrivate() you might encounter the following test exception:
org.mockito.exceptions.misusing.NotAMockException: Argument passed to verify() is of type Class and is not a mock! Make sure you place the parenthesis correctly! See the examples of correct verifications: verify(mock).someMethod(); verify(mock, times(10)).someMethod(); verify(mock, atLeastOnce()).someMethod(); |
The code should be refactored to manually verify the required call.
For example:
PowerMockito.when(MyClass.staticCall(any())).thenAnswer(invocation -> "value"); ... PowerMockito.verifyStatic(MyClass.class, times(1)); MyClass.staticCall(any()); |
Updated code:
int counter[] = new int[]{0}; PowerMockito.when(MyClass.staticCall(any())).thenAnswer(invocation -> { counter[0]++; return "value"; }); ... assertEquals(1, counter[0]); |
For verifyPrivate() the only solution is to manually verify the required call since Mockito does not support mocking private methods.
For example:
PowerMockito.mockStatic(MyClass.class); PowerMockito.when(MyClass.class, "privateStatic", any()).thenAnswer(invocation -> inv.callRealMethod()); ... PowerMockito.verifyPrivate(MyClass.class, times(1)).invoke("privateStatic"); |
Updated code:
PowerMockito.mockStatic(MyClass.class); int counter[] = new int[]{0}; PowerMockito.when(MyClass.class, "privateStatic", any()).thenAnswer(invocation -> { counter[0]++; return inv.callRealMethod(); }); ... assertEquals(1, counter[0]); |
PowerMock code:
PowerMockito.mockStatic(MyClass.class); PowerMockito.when(MyClass.staticCall(any())).thenReturn("value"); // test code PowerMockito.verifyStatic(MyClass.class, times(1)); MyClass.staticCall(any()); |
Code converted to Mockito:
try (MockedStatic<FunctionsToMock> mocked = mockStatic(FunctionsToMock.class)) { mocked.when(() -> FunctionsToMock.staticCall(any())).thenReturn("value"); // test code mocked.verify(() -> FunctionsToMock.staticCall(any()), times(1)); } |
PowerMock code:
FunctionsToMock mock = Mockito.mock(FunctionsToMock.class); PowerMockito.whenNew(FunctionsToMock.class).withAnyArguments().thenReturn(mock); when(mock.calculate()).thenReturn(1); // test code |
Code converted to Mockito:
try (MockedConstruction<FunctionsToMock> mocked = mockConstruction(FunctionsToMock.class, (mock, context) -> { when(mock.calculate()).thenReturn(1); })) { // test code } |
The following cases are not supported by Mockito:
Mockito also does not recommend static mocking any class of the JDK.
To correctly process and analyze a file, Jtest must be able to match the file name you provided in the testing scope (i.e. the file name in your project) with the file name in the source control system. For this reason, if you are using a case-sensitive source control system, such a Git, you need to ensure that the file name capitalization is identical.
On Windows, a file path longer than 250 characters may prevent accessing the file. If your workspace is deeply nested in the folder structure, the path to some UTA files may exceed 250 characters. If the files that are key to test execution cannot be accessed, test execution fails.
To ensure that the path to the UTA files does not exceed the limit, you may consider moving your workspace folder higher in the folder hierarchy.
In rare cases, the Jtest run configuration may not work due to a known issue in some IntelliJ versions (see https://youtrack.jetbrains.com/issue/IDEA-223124 for details). If this happens, you need restart your IDE. The Jtest run configuration will be working after the restart.
When using latest Ubuntu Linux (21.10 or newer), with Snap-based Firefox browser as default, the Eclipse IDE may be unable to show HTML content correctly (see also: https://github.com/eclipse-platform/eclipse.platform.swt/issues/221). There are two workarounds:
Note: In order to configure Firefox as an "external web browser", use the following settings:
Location: /usr/bin/env
Parameters: firefox %URL%