Skip to content

Commit 98647d8

Browse files
committed
provide test/example
1 parent 63bb19f commit 98647d8

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,24 @@
5353

5454
<dependency>
5555
<groupId>org.jetbrains.kotlin</groupId>
56-
<artifactId>kotlin-test</artifactId>
57-
<version>${kotlin.version}</version>
56+
<artifactId>kotlin-test-junit5</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>com.tngtech.jgiven</groupId>
62+
<artifactId>jgiven-junit5</artifactId>
63+
<version>${jgiven.version}</version>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.slf4j</groupId>
69+
<artifactId>slf4j-simple</artifactId>
70+
<version>1.7.30</version>
5871
<scope>test</scope>
5972
</dependency>
73+
6074
</dependencies>
6175

6276
<repositories>

src/test/kotlin/.gitkeep

Whitespace-only changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.toolisticon.testing.jgiven
2+
3+
import com.tngtech.jgiven.Stage
4+
import com.tngtech.jgiven.annotation.ScenarioState
5+
import com.tngtech.jgiven.annotation.ScenarioState.Resolution.NAME
6+
import com.tngtech.jgiven.junit5.SimpleScenarioTest
7+
import org.junit.jupiter.api.Test
8+
import kotlin.test.assertEquals
9+
10+
/**
11+
* Simple example using GIVEN/WHEN/THEN extensions, the step() lambda and the all open annotation.
12+
*/
13+
class CalculatorExampleTest : SimpleScenarioTest<CalculatorStage>() {
14+
15+
@Test
16+
internal fun `calculator adds two numbers`() {
17+
GIVEN
18+
.`the first number is $`(4)
19+
.AND
20+
.`the second number is $`(7)
21+
22+
WHEN
23+
.`both numbers are added`()
24+
25+
THEN
26+
.`the sum is $`(11)
27+
}
28+
}
29+
30+
@JGivenKotlinStage
31+
class CalculatorStage : Stage<CalculatorStage>() {
32+
33+
@ScenarioState(resolution = NAME)
34+
var firstNumber: Int = 0
35+
36+
@ScenarioState(resolution = NAME)
37+
var secondNumber: Int = 0
38+
39+
@ScenarioState(resolution = NAME)
40+
var sum: Int = 0
41+
42+
fun `the first number is $`(n: Int) = step {
43+
this.firstNumber = n
44+
}
45+
46+
fun `the second number is $`(n: Int) = step {
47+
this.secondNumber = n
48+
}
49+
50+
fun `both numbers are added`() = step {
51+
sum = firstNumber + secondNumber
52+
}
53+
54+
fun `the sum is $`(expected: Int) = step {
55+
assertEquals(expected, sum)
56+
}
57+
58+
}

src/test/resources/.gitkeep

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.slf4j.simpleLogger.defaultLogLevel = info
2+
org.slf4j.simpleLogger.showShortLogName = true
3+
org.slf4j.simpleLogger.levelInBrackets = true

0 commit comments

Comments
 (0)