Skip to content

Commit

Permalink
changed to read packageName, className and testName form the fully qu…
Browse files Browse the repository at this point in the history
…alified className; extended test to verify
  • Loading branch information
ralfhergert committed Dec 20, 2017
1 parent 2aefb31 commit 644c061
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public static List<TestRun> convert(InputStream artifactStream) throws JAXBExcep
}
for (JUnitTestCase testCase : testCases) {
testResults.add(DTOFactory.getInstance().newDTO(TestRun.class)
//.setClassName(testCase.getClassName())
.setDuration((long)(testCase.getTime() * 1000))
.setModuleName(testSuite.getName())
.setPackageName(extractPackageName(testCase.getClassName()))
.setClassName(extractSimpleClassName(testCase.getClassName()))
.setTestName(testCase.getName())
.setDuration((long)(testCase.getTime() * 1000))
.setStarted(startTime)
.setResult(convert(testCase))
//.setModuleName(testSuite.getName())
.setPackageName(extractPackageName(testSuite.getName()))
.setError(extractTestRunError(testCase)));
}
}
Expand All @@ -89,6 +89,11 @@ public static String extractPackageName(String className) {
return index > -1 ? className.substring(0, index) : className;
}

public static String extractSimpleClassName(String className) {
int index = className.lastIndexOf(".");
return index > -1 ? className.substring(index + 1) : className;
}

public static TestRunError extractTestRunError(JUnitTestCase testCase) {
if (testCase.getFailures() != null && !testCase.getFailures().isEmpty()) {
JUnitFailure failure = testCase.getFailures().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public static List<TestRun> convert(InputStream artifactStream) throws JAXBExcep
startTime = new Date().getTime();
}
for (NUnitTestCase testCase : testCases) {
final String fullyQualifiedClassName = extractFullyQualifiedClassName(testCase.getName());
testRuns.add(DTOFactory.getInstance().newDTO(TestRun.class)
.setTestName(testCase.getName())
.setPackageName(extractPackageName(fullyQualifiedClassName))
.setClassName(extractSimpleClassName(fullyQualifiedClassName))
.setTestName(extractTestName(testCase.getName()))
.setDuration((long)(testCase.getTime() * 1000))
.setStarted(startTime)
.setResult(convert(testCase))
.setPackageName(extractPackageName(testCase.getName()))
.setError(extractTestRunError(testCase)));
}
}
Expand All @@ -82,9 +84,24 @@ public static TestRunResult convert(NUnitTestCase testCase) {
}
}

public static String extractPackageName(String className) {
int index = className.lastIndexOf(".");
return index > -1 ? className.substring(0, index) : className;
public static String extractFullyQualifiedClassName(String testCaseName) {
int index = testCaseName.lastIndexOf(".");
return index > -1 ? testCaseName.substring(0, index) : testCaseName;
}

public static String extractSimpleClassName(String fullyQualifiedClassName) {
int index = fullyQualifiedClassName.lastIndexOf(".");
return index > -1 ? fullyQualifiedClassName.substring(index + 1) : fullyQualifiedClassName;
}

public static String extractPackageName(String fullyQualifiedClassName) {
int index = fullyQualifiedClassName.lastIndexOf(".");
return index > -1 ? fullyQualifiedClassName.substring(0, index) : fullyQualifiedClassName;
}

public static String extractTestName(String testCaseName) {
int index = testCaseName.lastIndexOf(".");
return index > -1 ? testCaseName.substring(index + 1) : testCaseName;
}

public static TestRunError extractTestRunError(NUnitTestCase testCase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public void testConversionFromJUnitXMLIntoOctaneModel() throws JAXBException {
final List<TestRun> tests = OctaneJUnitTestResultsBuilder.convert(getClass().getClassLoader().getResourceAsStream("junit.testResults.xml"));
Assert.assertNotNull("tests should not be null", tests);
Assert.assertEquals("number of tests", 3, tests.size());
TestRun testRun = tests.get(0);
Assert.assertEquals("package name", "com.haufelexware.report.junit", testRun.getPackageName());
Assert.assertEquals("class name", "JUnitReportParserTest", testRun.getClassName());
Assert.assertEquals("test name", "testComparison", testRun.getTestName());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ public void testConversionFromNUnitXMLIntoOctaneModel() throws JAXBException {
final List<TestRun> tests = OctaneNUnitTestResultsBuilder.convert(getClass().getClassLoader().getResourceAsStream("nunit.testResults.xml"));
Assert.assertNotNull("tests should not be null", tests);
Assert.assertEquals("number of tests", 6, tests.size());
TestRun testRun = tests.get(0);
Assert.assertEquals("package name", "Haufe.PT.DataGeneration.Tests", testRun.getPackageName());
Assert.assertEquals("class name", "CommandLineOptionsTests", testRun.getClassName());
Assert.assertEquals("test name", "TestParseGenerators_MultipleGenerators_OneIncorrect", testRun.getTestName());
}
}

0 comments on commit 644c061

Please sign in to comment.