Add SimpleTestRunner as a test runner.
continuous-integration/drone/tag Build is failing
Details
continuous-integration/drone/tag Build is failing
Details
parent
1549f85a49
commit
9a14ea6486
@ -0,0 +1,6 @@
|
|||||||
|
package space.kklochko.simple_jbdd.tests.runners;
|
||||||
|
|
||||||
|
public abstract class AbstractTestRunner {
|
||||||
|
public abstract boolean run();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
package space.kklochko.simple_jbdd.tests.runners;
|
||||||
|
|
||||||
|
import space.kklochko.simple_jbdd.tests.Test;
|
||||||
|
import space.kklochko.simple_jbdd.tests.commands.AbstractTestCommand;
|
||||||
|
|
||||||
|
public class SimpleTestRunner extends AbstractTestRunner {
|
||||||
|
AbstractTestCommand<Test> command;
|
||||||
|
|
||||||
|
public SimpleTestRunner(AbstractTestCommand<Test> command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean run() {
|
||||||
|
try {
|
||||||
|
return getCommand().test();
|
||||||
|
}catch (AssertionError e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractTestCommand<Test> getCommand() {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommand(AbstractTestCommand<Test> command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,87 @@
|
|||||||
|
package space.kklochko.simple_jbdd.tests.runners
|
||||||
|
|
||||||
|
import space.kklochko.simple_jbdd.test_examples.tests.SimpleFailedThenTest
|
||||||
|
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
|
||||||
|
import space.kklochko.simple_jbdd.tests.commands.SimpleTestCommand
|
||||||
|
import space.kklochko.simple_jbdd.tests.factories.TestCommandFactory
|
||||||
|
import spock.lang.Narrative
|
||||||
|
import spock.lang.Specification
|
||||||
|
import spock.lang.Subject
|
||||||
|
import spock.lang.Title
|
||||||
|
|
||||||
|
@Narrative("""The runner must return a result of test, so
|
||||||
|
those tests check if passed and failed test generate the right result.
|
||||||
|
""")
|
||||||
|
@Title("Unit tests for SimpleTestRunner")
|
||||||
|
class SimpleTestRunnerSpec extends Specification {
|
||||||
|
def "The test with then has been passed."() {
|
||||||
|
given: "I have a testCommand"
|
||||||
|
def test = Stub(SimpleTestCommand)
|
||||||
|
test.test() >>> [true]
|
||||||
|
|
||||||
|
and: "I have a test runner"
|
||||||
|
@Subject
|
||||||
|
def runner = new SimpleTestRunner(test)
|
||||||
|
|
||||||
|
when: "The testCommand has been run"
|
||||||
|
def result = runner.run()
|
||||||
|
|
||||||
|
then: "The result is true"
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
def "The real test with then has been passed."() {
|
||||||
|
given: "I have a test and a factory"
|
||||||
|
def aTest = new SimpleThenTest()
|
||||||
|
def factory = new TestCommandFactory();
|
||||||
|
|
||||||
|
and: "I have a testCommand"
|
||||||
|
def test = factory.create(aTest)
|
||||||
|
|
||||||
|
and: "I have a test runner"
|
||||||
|
@Subject
|
||||||
|
def runner = new SimpleTestRunner(test)
|
||||||
|
|
||||||
|
when: "The testCommand has been run"
|
||||||
|
def result = runner.run()
|
||||||
|
|
||||||
|
then: "The result is true"
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
def "The test with then that has not been passed."() {
|
||||||
|
given: "I have a failed testCommand"
|
||||||
|
def test = Stub(SimpleTestCommand)
|
||||||
|
test.test() >> { assert 1 == 0 }
|
||||||
|
|
||||||
|
and: "I have a test runner"
|
||||||
|
@Subject
|
||||||
|
def runner = new SimpleTestRunner(test)
|
||||||
|
|
||||||
|
when: "The testCommand has been run"
|
||||||
|
def result = runner.run()
|
||||||
|
|
||||||
|
then: "The result is true"
|
||||||
|
!result
|
||||||
|
}
|
||||||
|
|
||||||
|
def "The real test with then has not been passed."() {
|
||||||
|
given: "I have a test and a factory"
|
||||||
|
def aTest = new SimpleFailedThenTest()
|
||||||
|
def factory = new TestCommandFactory();
|
||||||
|
|
||||||
|
and: "I have a testCommand"
|
||||||
|
def test = factory.create(aTest)
|
||||||
|
|
||||||
|
and: "I have a test runner"
|
||||||
|
@Subject
|
||||||
|
def runner = new SimpleTestRunner(test)
|
||||||
|
|
||||||
|
when: "The testCommand has been run"
|
||||||
|
def result = runner.run()
|
||||||
|
|
||||||
|
then: "The result is true"
|
||||||
|
!result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue