Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JUnit 5 support #55

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ cp /root/pom.xml $2

# Temporarily un-ignore tests
find $2/src/test/kotlin -type f -name '*Test.kt' -execdir cp {} {}.bak \;
find $2/src/test/kotlin -type f -name '*Test.kt' -exec sed -i "s/@Ignore(.*)//g;s/@Ignore//g;" {} \;
find $2/src/test/kotlin -type f -name '*Test.kt' -exec sed -i "s/@Ignore(.*)//g;s/@Ignore//g;" {} \; # for JUnit 4
find $2/src/test/kotlin -type f -name '*Test.kt' -exec sed -i "s/@Disabled(.*)//g;s/@Disabled//g;" {} \; # for JUnit 5

# See Dockerfile for details
java -jar /opt/test-runner/autotest-runner.jar $1 $2 $3
Expand Down
20 changes: 19 additions & 1 deletion examples/template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -57,7 +75,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
22 changes: 22 additions & 0 deletions tests/example-all-fail-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm") version "1.9.0"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("passed", "failed", "skipped")
}
}
61 changes: 61 additions & 0 deletions tests/example-all-fail-junit5/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": 2,
"status": "fail",
"message": "",
"tests": [
{
"name": "divisible by 400 but not by 125",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 100, not divisible by 400",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 400",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "not divisible by 4",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 2, not divisible by 4",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 4 and 5",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 4, not divisible by 100",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 200, not divisible by 400",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 100 but not by 3",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
}
]
}
5 changes: 5 additions & 0 deletions tests/example-all-fail-junit5/src/main/kotlin/Leap.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data class Year(private val year: Int) {
val isLeap: Boolean by lazy { ! (divisibleBy(4) && (divisibleBy(400) || !divisibleBy(100))) }

private fun divisibleBy(i: Int) = year % i == 0
}
45 changes: 45 additions & 0 deletions tests/example-all-fail-junit5/src/test/kotlin/LeapTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue

class LeapTest {
@Test
fun `not divisible by 4`() = assertYearIsCommon(2015)

@Disabled
@Test
fun `divisible by 2, not divisible by 4`() = assertYearIsCommon(1970)

@Disabled
@Test
fun `divisible by 4, not divisible by 100`() = assertYearIsLeap(1996)

@Disabled
@Test
fun `divisible by 4 and 5`() = assertYearIsLeap(1960)

@Disabled
@Test
fun `divisible by 100, not divisible by 400`() = assertYearIsCommon(2100)

@Disabled
@Test
fun `divisible by 100 but not by 3`() = assertYearIsCommon(1900)

@Disabled
@Test
fun `divisible by 400`() = assertYearIsLeap(2000)

@Disabled
@Test
fun `divisible by 400 but not by 125`() = assertYearIsLeap(2400)

@Disabled
@Test
fun `divisible by 200, not divisible by 400`() = assertYearIsCommon(1800)
}

private fun assertYearIsLeap(year: Int) = assertTrue(Year(year).isLeap)

private fun assertYearIsCommon(year: Int) = assertFalse(Year(year).isLeap)
22 changes: 22 additions & 0 deletions tests/example-empty-file-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm") version "1.9.0"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("passed", "failed", "skipped")
}
}
6 changes: 6 additions & 0 deletions tests/example-empty-file-junit5/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 2,
"status": "error",
"message": "[ERROR] src/test/kotlin/LeapTest.kt:[43,54] Unresolved reference: Year\n[ERROR] src/test/kotlin/LeapTest.kt:[45,57] Unresolved reference: Year",
"tests": []
}
45 changes: 45 additions & 0 deletions tests/example-empty-file-junit5/src/test/kotlin/LeapTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue

class LeapTest {
@Test
fun `not divisible by 4`() = assertYearIsCommon(2015)

@Disabled
@Test
fun `divisible by 2, not divisible by 4`() = assertYearIsCommon(1970)

@Disabled
@Test
fun `divisible by 4, not divisible by 100`() = assertYearIsLeap(1996)

@Disabled
@Test
fun `divisible by 4 and 5`() = assertYearIsLeap(1960)

@Disabled
@Test
fun `divisible by 100, not divisible by 400`() = assertYearIsCommon(2100)

@Disabled
@Test
fun `divisible by 100 but not by 3`() = assertYearIsCommon(1900)

@Disabled
@Test
fun `divisible by 400`() = assertYearIsLeap(2000)

@Disabled
@Test
fun `divisible by 400 but not by 125`() = assertYearIsLeap(2400)

@Disabled
@Test
fun `divisible by 200, not divisible by 400`() = assertYearIsCommon(1800)
}

private fun assertYearIsLeap(year: Int) = assertTrue(Year(year).isLeap)

private fun assertYearIsCommon(year: Int) = assertFalse(Year(year).isLeap)
Empty file.
23 changes: 23 additions & 0 deletions tests/example-partial-fail-junit5/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"blurb": "Given a year, report if it is a leap year.",
"authors": ["sdavids13"],
"contributors": [
"dector",
"eparovyshnaya",
"jtigger",
"lihofm",
"mdowds",
"nithia",
"sjwarner-bp",
"SleeplessByte",
"stkent",
"uzilan"
],
"files": {
"solution": ["src/main/kotlin/Leap.kt"],
"test": ["src/test/kotlin/LeapTest.kt"],
"example": [".meta/src/reference/kotlin/Leap.kt"]
},
"source": "JavaRanch Cattle Drive, exercise 3",
"source_url": "http://www.javaranch.com/leap.jsp"
}
1 change: 1 addition & 0 deletions tests/example-partial-fail-junit5/.meta/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.6.0
22 changes: 22 additions & 0 deletions tests/example-partial-fail-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm") version "1.9.0"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("passed", "failed", "skipped")
}
}
61 changes: 61 additions & 0 deletions tests/example-partial-fail-junit5/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": 2,
"status": "fail",
"message": "",
"tests": [
{
"name": "divisible by 400 but not by 125",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 100, not divisible by 400",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 400",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "not divisible by 4",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 2, not divisible by 4",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 4 and 5",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 4, not divisible by 100",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 200, not divisible by 400",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 100 but not by 3",
"status": "pass",
"message": "",
"output": ""
}
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading