Class CoverageApiClient
java.lang.Object
com.parasoft.coverage.integration.api.CoverageApiClient
User-facing client for directly reporting coverage session and test lifecycle
events.
Most users should prefer the JUnit integration modules. Use this client only
when a test is launched manually, such as from a main method or a
custom test harness.
Typical standalone usage:
CoverageApiClient client = CoverageApiClient.createFromSettings();
String sessionId = client.startSession();
CoverageTestContext context = client.startTest("ExampleTest", "runsFromMain");
try {
// Execute the code under test here. Send context.getCurrentTestOperatorIdHeader()
// as HTTP headers when calling an application under test.
client.stopTest("ExampleTest", "runsFromMain", context, CoverageTestResult.PASS, null);
} catch (RuntimeException e) {
client.stopTest("ExampleTest", "runsFromMain", context, CoverageTestResult.FAIL, e.getMessage());
throw e;
} finally {
client.stopSession();
client.publishResults(sessionId, null, null, null);
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic CoverageApiClientCreates a client for directly reporting coverage events.static CoverageApiClientCreates a client fromcoverage-integration.propertiesand system properties.voidpublishResults(String sessionId, String testConfig, String userId, String toolName) Publishes coverage results for a finished session.Starts a coverage session.Starts coverage tracking for a test.voidStops the current coverage session.voidstopTest(String test, String testCase, CoverageTestContext testContext, CoverageTestResult result, String message) Stops coverage tracking for a test.
-
Method Details
-
createFromSettings
Creates a client fromcoverage-integration.propertiesand system properties.- Returns:
- a coverage API client
-
create
public static CoverageApiClient create(String ctpBaseUrl, Long environmentId, String userId, String sessionTag) Creates a client for directly reporting coverage events.- Parameters:
ctpBaseUrl- CTP base URLenvironmentId- CTP environment identifieruserId- user identifier to send to CTPsessionTag- optional session tag- Returns:
- a coverage API client
-
startSession
Starts a coverage session.- Returns:
- the coverage session identifier returned by CTP, or
nullwhen no session identifier is available
-
startTest
Starts coverage tracking for a test.- Parameters:
test- test identifier, usually the test class nametestCase- test case identifier, usually the test method name- Returns:
- context returned from the CTP
/test/startAPI
-
stopTest
public void stopTest(String test, String testCase, CoverageTestContext testContext, CoverageTestResult result, String message) Stops coverage tracking for a test.- Parameters:
test- test identifier, usually the test class nametestCase- test case identifier, usually the test method nametestContext- context returned bystartTest(String, String)result- final test resultmessage- optional result message, such as a failure summary
-
stopSession
public void stopSession()Stops the current coverage session. -
publishResults
Publishes coverage results for a finished session.- Parameters:
sessionId- coverage session identifier returned bystartSession()testConfig- optional test configuration nameuserId- optional user identifiertoolName- optional tool name
-