-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* handle nested test suites * add unit tests * ensure consistency of number of tests, errors, and failures
- Loading branch information
Showing
6 changed files
with
293 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/de/tum/in/www1/jenkins/notifications/model/TestsuiteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package de.tum.in.www1.jenkins.notifications.model; | ||
|
||
import com.sun.xml.bind.v2.ContextFactory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.Unmarshaller; | ||
import java.io.*; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class TestsuiteTest { | ||
|
||
@Test | ||
void testFlattenNestedSuiteSuccessful() throws Exception { | ||
Testsuite input = loadTestSuite(Paths.get("nested_successful.xml")); | ||
assertEquals(2, input.getTestSuites().size()); | ||
|
||
Testsuite flattened = input.flatten(); | ||
assertNull(flattened.getTestSuites()); | ||
|
||
assertEquals(12, flattened.getTests()); | ||
assertEquals(12, flattened.getTestCases().size()); | ||
assertEquals(0, flattened.getErrors()); | ||
assertEquals(0, flattened.getFailures()); | ||
} | ||
|
||
@Test | ||
void testFlattenBuildTestCaseNames() throws Exception { | ||
Testsuite testSuite = loadTestSuite(Paths.get("nested_successful.xml")).flatten(); | ||
|
||
List<String> expectedTestCaseNames = new ArrayList<>(); | ||
expectedTestCaseNames.add("Properties.Checked by SmallCheck.Testing filtering in A"); | ||
expectedTestCaseNames.add("Testing selectAndReflectA (0,0) []"); | ||
|
||
List<String> actualTestCaseNames = testSuite.getTestCases().stream().map(TestCase::getName).collect(Collectors.toList()); | ||
|
||
for (String testCaseName : expectedTestCaseNames) { | ||
Optional<String> testCase = actualTestCaseNames.stream().filter(testCaseName::equals).findFirst(); | ||
assertTrue(testCase.isPresent(), String.format("Did not find test case '%s' in %s", testCaseName, actualTestCaseNames)); | ||
} | ||
} | ||
|
||
@Test | ||
void testFlattenNestedSuiteWithFailures() throws Exception { | ||
Testsuite input = loadTestSuite(Paths.get("nested_with_failures.xml")); | ||
assertEquals(2, input.getTestSuites().size()); | ||
|
||
Testsuite flattened = input.flatten(); | ||
assertNull(flattened.getTestSuites()); | ||
|
||
assertEquals(12, flattened.getTests()); | ||
assertEquals(12, flattened.getTestCases().size()); | ||
assertEquals(2, flattened.getFailures()); | ||
assertEquals(1, flattened.getErrors()); | ||
} | ||
|
||
private Testsuite loadTestSuite(final Path reportXml) throws JAXBException { | ||
Path resourcePath = new File("testsuite_examples").toPath().resolve(reportXml); | ||
URL resource = getClass().getClassLoader().getResource(resourcePath.toString()); | ||
|
||
final JAXBContext context = createJAXBContext(); | ||
final Unmarshaller unmarshaller = context.createUnmarshaller(); | ||
return (Testsuite) unmarshaller.unmarshal(resource); | ||
} | ||
|
||
private JAXBContext createJAXBContext() throws JAXBException { | ||
return ContextFactory.createContext(ObjectFactory.class.getPackage().getName(), ObjectFactory.class.getClassLoader(), null); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/resources/testsuite_examples/nested_successful.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version='1.0' ?> | ||
<testsuite name="Tests" tests="12"> | ||
<testsuite name="Properties" tests="9"> | ||
<testsuite name="Checked by SmallCheck" tests="6"> | ||
<testcase name="Testing filtering in A" time="0.004" classname="Tests.Properties.Checked by SmallCheck" /> | ||
<testcase name="Testing mapping in A" time="0.000" classname="Tests.Properties.Checked by SmallCheck" /> | ||
<testcase name="Testing filtering in B" time="0.000" classname="Tests.Properties.Checked by SmallCheck" /> | ||
<testcase name="Testing mapping in B" time="0.000" classname="Tests.Properties.Checked by SmallCheck" /> | ||
<testcase name="Testing filtering in C" time="0.003" classname="Tests.Properties.Checked by SmallCheck" /> | ||
<testcase name="Testing mapping in C" time="0.000" classname="Tests.Properties.Checked by SmallCheck" /> | ||
</testsuite> | ||
<testsuite name="Checked by QuickCheck" tests="3"> | ||
<testcase name="Testing A against sample solution" time="0.001" classname="Tests.Properties.Checked by QuickCheck" /> | ||
<testcase name="Testing B against sample solution" time="0.001" classname="Tests.Properties.Checked by QuickCheck" /> | ||
<testcase name="Testing C against sample solution" time="0.001" classname="Tests.Properties.Checked by QuickCheck" /> | ||
</testsuite> | ||
</testsuite> | ||
<!-- artificially introduce unnamed test suite --> | ||
<testsuite tests="3"> | ||
<testcase name="Testing selectAndReflectA (0,0) []" time="0.000" classname="Tests.Unit Tests" /> | ||
<testcase name="Testing selectAndReflectB (0,1) [(0,0)]" time="0.000" classname="Tests.Unit Tests" /> | ||
<testcase name="Testing selectAndReflectC (0,1) [(-1,-1)]" time="0.000" classname="Tests.Unit Tests" /> | ||
<testsuite name="Empty Testsuite" tests="0"> | ||
<!-- intentionally empty --> | ||
</testsuite> | ||
</testsuite> | ||
</testsuite> |
43 changes: 43 additions & 0 deletions
43
src/test/resources/testsuite_examples/nested_with_failures.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version='1.0' ?> | ||
<testsuite name="Tests" tests="12"> | ||
<testsuite name="Properties" tests="9"> | ||
<testsuite name="Checked by SmallCheck" tests="6"> | ||
<testcase name="Testing filtering in A" time="0.000" classname="Tests.Properties.Checked by SmallCheck"> | ||
<failure>there exist (0,1) [(1,0)] such that | ||
condition is false | ||
</failure> | ||
</testcase> | ||
<testcase name="Testing mapping in A" time="0.000" classname="Tests.Properties.Checked by SmallCheck"/> | ||
<testcase name="Testing filtering in B" time="0.000" classname="Tests.Properties.Checked by SmallCheck"/> | ||
<testcase name="Testing mapping in B" time="0.000" classname="Tests.Properties.Checked by SmallCheck"/> | ||
<testcase name="Testing filtering in C" time="0.002" classname="Tests.Properties.Checked by SmallCheck"/> | ||
<testcase name="Testing mapping in C" time="0.000" classname="Tests.Properties.Checked by SmallCheck"> | ||
<error>Some error message</error> | ||
</testcase> | ||
</testsuite> | ||
<testsuite name="Checked by QuickCheck" tests="3"> | ||
<testcase name="Testing A against sample solution" time="0.000" | ||
classname="Tests.Properties.Checked by QuickCheck"> | ||
<failure>*** Failed! (after 5 tests and 5 shrinks): | ||
|
||
>>>>>>>>>>>>>> expected | ||
[ ( 1 , 0 ) ] | ||
>>>>>>>>>>>>>> but got | ||
[ ( -2 , 0 ) ] | ||
(0,1) | ||
[(1,0)] | ||
Use --quickcheck-replay=220998 to reproduce. | ||
</failure> | ||
</testcase> | ||
<testcase name="Testing B against sample solution" time="0.000" | ||
classname="Tests.Properties.Checked by QuickCheck"/> | ||
<testcase name="Testing C against sample solution" time="0.000" | ||
classname="Tests.Properties.Checked by QuickCheck"/> | ||
</testsuite> | ||
</testsuite> | ||
<testsuite name="Unit Tests" tests="3"> | ||
<testcase name="Testing selectAndReflectA (0,0) []" time="0.000" classname="Tests.Unit Tests"/> | ||
<testcase name="Testing selectAndReflectB (0,1) [(0,0)]" time="0.000" classname="Tests.Unit Tests"/> | ||
<testcase name="Testing selectAndReflectC (0,1) [(-1,-1)]" time="0.000" classname="Tests.Unit Tests"/> | ||
</testsuite> | ||
</testsuite> |