Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1b85e3771 | ||
|
|
0683be643f | ||
|
|
e67bdc4bb0 | ||
|
|
9a14ea6486 | ||
|
|
1549f85a49 |
+24
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: gradle
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: test
|
||||||
|
image: gradle:8.3.0-jdk17-graal
|
||||||
|
commands:
|
||||||
|
- gradle assemble
|
||||||
|
- gradle check
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: maven
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: test
|
||||||
|
image: maven:3.9.4-eclipse-temurin-17-alpine
|
||||||
|
commands:
|
||||||
|
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
||||||
|
- mvn test -B
|
||||||
|
|
||||||
@@ -28,6 +28,11 @@ public class BlockDecorator<T extends Test> extends AbstractDecorator<T> {
|
|||||||
method.invoke(getCommand().getObject());
|
method.invoke(getCommand().getObject());
|
||||||
return true;
|
return true;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
|
Throwable exception = e.getCause();
|
||||||
|
|
||||||
|
if(exception instanceof AssertionError)
|
||||||
|
throw (AssertionError) exception;
|
||||||
|
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
private AbstractTestCommand<Test> command;
|
||||||
|
|
||||||
|
public SimpleTestRunner(AbstractTestCommand<Test> command) {
|
||||||
|
setCommand(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package space.kklochko.simple_jbdd.tests.runners
|
||||||
|
|
||||||
|
import space.kklochko.simple_jbdd.test_examples.tests.SimpleFailedThenTest
|
||||||
|
import space.kklochko.simple_jbdd.test_examples.tests.SimpleGivenWhenThenTest
|
||||||
|
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
|
||||||
|
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTestWithoutTitle
|
||||||
|
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("Integrated tests for SimpleTestRunner with TestCommandFactory and test examples")
|
||||||
|
class IntegratedSimpleTestRunnerSpec extends Specification {
|
||||||
|
def "The real test has been run."() {
|
||||||
|
given: "I have a factory"
|
||||||
|
def factory = new TestCommandFactory();
|
||||||
|
|
||||||
|
and: "I have a testCommand created from a test object"
|
||||||
|
def test = factory.create(testObject)
|
||||||
|
|
||||||
|
and: "I have a test runner"
|
||||||
|
@Subject
|
||||||
|
def runner = new SimpleTestRunner(test)
|
||||||
|
|
||||||
|
when: "The testCommand has been run"
|
||||||
|
def result = runner.run()
|
||||||
|
|
||||||
|
then: "Checking that the test result is expected"
|
||||||
|
result == expectedResult
|
||||||
|
|
||||||
|
where: "Possible variants of tests"
|
||||||
|
testObject || expectedResult
|
||||||
|
new SimpleThenTest() || true
|
||||||
|
new SimpleGivenWhenThenTest() || true
|
||||||
|
new SimpleThenTestWithoutTitle() || true
|
||||||
|
new SimpleFailedThenTest() || false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package space.kklochko.simple_jbdd.tests.runners
|
||||||
|
|
||||||
|
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 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 false"
|
||||||
|
!result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user