1
1
Fork 0

Added automatic tests for junit samples

This commit is contained in:
Svetlana Isakova 2020-11-19 16:53:01 +01:00
parent 9116aa5bd0
commit 029d43da9c
3 changed files with 21 additions and 4 deletions

View File

@ -1,11 +1,14 @@
import atomictest.ERROR_TAG
import org.junit.Assert
import org.junit.runner.JUnitCore
import util.LINE_SEPARATOR
import util.normalizeLineSeparators
import java.io.*
import java.util.function.Consumer
abstract class AbstractTestExamples {
private val junit = JUnitCore()
protected fun testExample(fileName: String, main: Runnable) {
testExample(fileName, Consumer { main.run() })
}
@ -26,9 +29,9 @@ abstract class AbstractTestExamples {
}
}
protected fun testExercise(outputFileName: String, main: Consumer<Array<String>>) {
val output = File(outputFileName).readText()
testOutput(output, main, trim = false)
protected fun testUnitTest(testClass: Class<*>) {
val result = junit.run(testClass)
Assert.assertTrue(result.wasSuccessful())
}
private fun extractOutput(exampleCode: String, outputComment: String) =

View File

@ -1,7 +1,6 @@
import org.junit.After
import org.junit.Assert
import org.junit.runner.JUnitCore
import util.loadTraceContent
import util.resetTraceContent
import util.runAndCheckSystemOutput
import java.io.File

View File

@ -2206,6 +2206,21 @@ public class TestAllExamples extends AbstractTestExamples {
testExample("Preventing Failure/Unit Testing/Examples/src/UsingExpect.kt", unittesting.UsingExpectKt::main);
}
@Test
public void testSampleTest() {
testUnitTest(unittesting.SampleTest.class);
}
@Test
public void testLearnerTest() {
testUnitTest(unittesting.LearnerTest.class);
}
@Test
public void testStateMachineTest() {
testUnitTest(unittesting.StateMachineTest.class);
}
@Test
public void testTransform() {
testExample("Power Tools/Extension Lambdas/Examples/src/Transform.kt", extensionlambdas.TransformKt::main);