Skip to content

Commit 15c83db

Browse files
committed
Ended up testing things with mocks.. :(
1 parent 60e8153 commit 15c83db

File tree

18 files changed

+330
-72
lines changed

18 files changed

+330
-72
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = tab
6+
tab_width = 3
7+
max_line_length = 120
8+
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.gradle.kts]
13+
indent_size = 3

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ Kotest wrapper for using [Skippy](https://www.skippy.io) for test execution pred
22

33
Skippy uses JaCoCo coverage from past test executions to determine the tests that cover any modified code, and runs only the relevant tests.
44

5+
Requires JDK17+ (currently a requirement from Skippy).
6+
57
## Usage
68

79
In your `build.gradle.kts`:
810

911
```kotlin
1012
plugins {
11-
id("io.skippy") version "0.0.19"
13+
id("io.skippy") version "0.0.20"
1214
}
1315
```
1416

@@ -19,7 +21,5 @@ object KotestConfig : AbstractProjectConfig() {
1921
}
2022
```
2123

22-
Now, when you run tests using Gradle, Skippy will automatically skip tests that have not been affected by any change
24+
Now, when you run tests using Gradle, Skippy will automatically skip tests that have not been affected by any change
2325
since they were last executed successfully.
24-
25-
Currently the resolution of Skippy is entire files/classes. So every Spec is instrumented as one unit, and if any class it touches during testing changes, all tests will re-run.

build.gradle.kts

Lines changed: 115 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,132 @@
1-
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3-
4-
// issue https://youtrack.jetbrains.com/issue/KTIJ-19370
5-
@Suppress("DSL_SCOPE_VIOLATION")
61
plugins {
7-
java
82
`java-library`
9-
signing
103
`maven-publish`
11-
alias(libs.plugins.kotlin.jvm)
12-
jacoco
4+
signing
135
alias(libs.plugins.skippy)
6+
alias(libs.plugins.kotlin.jvm)
7+
`jvm-test-suite`
8+
}
9+
10+
group = "io.kotest.extensions"
11+
version = Ci.version
12+
13+
repositories {
14+
mavenLocal()
15+
mavenCentral()
16+
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots")
1417
}
1518

1619
dependencies {
1720
implementation(libs.kotest.framework.api)
1821
implementation(libs.skippy.core)
19-
20-
testImplementation(libs.kotest.runner.junit5)
21-
testImplementation(libs.kotest.framework.datatest)
22-
testImplementation(libs.kotest.property)
22+
testImplementation(libs.mockk)
2323
}
2424

25-
tasks.withType<Test> {
26-
useJUnitPlatform()
25+
val signingKey: String? by project
26+
val signingPassword: String? by project
27+
28+
val publications: PublicationContainer = (extensions.getByName("publishing") as PublishingExtension).publications
29+
30+
signing {
31+
useGpgCmd()
32+
if (signingKey != null && signingPassword != null) {
33+
@Suppress("UnstableApiUsage")
34+
useInMemoryPgpKeys(signingKey, signingPassword)
35+
}
36+
if (Ci.isRelease) {
37+
sign(publications)
38+
}
2739
}
2840

29-
tasks.withType<KotlinCompile> {
30-
kotlinOptions.jvmTarget = libs.versions.jvm.get()
41+
java {
42+
withJavadocJar()
43+
withSourcesJar()
44+
toolchain {
45+
languageVersion.set(JavaLanguageVersion.of(17))
46+
}
3147
}
3248

33-
repositories {
34-
mavenLocal()
35-
mavenCentral()
36-
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots")
49+
publishing {
50+
repositories {
51+
maven {
52+
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
53+
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
54+
name = "deploy"
55+
url = if (Ci.isRelease) releasesRepoUrl else snapshotsRepoUrl
56+
credentials {
57+
username = System.getenv("OSSRH_USERNAME") ?: ""
58+
password = System.getenv("OSSRH_PASSWORD") ?: ""
59+
}
60+
}
61+
}
62+
63+
publications {
64+
register("mavenJava", MavenPublication::class) {
65+
from(components["java"])
66+
pom {
67+
name.set("kotest-extensions-skippy")
68+
description.set("Kotest extension for Skippy")
69+
url.set("https://www.github.com/kotest/kotest-extensions-skippy")
70+
71+
scm {
72+
connection.set("scm:git:http://www.github.com/kotest/kotest-extensions-skippy")
73+
developerConnection.set("scm:git:http://github.com/kantis")
74+
url.set("https://www.github.com/kotest/kotest-extensions-skippy")
75+
}
76+
77+
licenses {
78+
license {
79+
name.set("The Apache 2.0 License")
80+
url.set("https://opensource.org/licenses/Apache-2.0")
81+
}
82+
}
83+
84+
developers {
85+
developer {
86+
id.set("sksamuel")
87+
name.set("Stephen Samuel")
88+
email.set("[email protected]")
89+
}
90+
91+
developer {
92+
id.set("Kantis")
93+
name.set("Emil Kantis")
94+
email.set("[email protected]")
95+
}
96+
}
97+
}
98+
}
99+
}
37100
}
38101

102+
@Suppress("UnstableApiUsage")
103+
testing {
104+
suites {
105+
val test by getting(JvmTestSuite::class) {
106+
useJUnitJupiter()
107+
dependencies {
108+
implementation(libs.kotest.runner.junit5)
109+
}
110+
}
111+
112+
val integrationTest by registering(JvmTestSuite::class) {
113+
testType.set(TestSuiteType.INTEGRATION_TEST)
114+
115+
dependencies {
116+
implementation(project())
117+
implementation(libs.kotest.runner.junit5)
118+
implementation(gradleTestKit())
119+
}
120+
121+
useJUnitJupiter()
122+
123+
targets {
124+
all {
125+
testTask.configure {
126+
mustRunAfter(test)
127+
}
128+
}
129+
}
130+
}
131+
}
132+
}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}

buildSrc/src/main/kotlin/Ci.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object Ci {
2+
3+
// this is the version used for building snapshots
4+
// .GITHUB_RUN_NUMBER-snapshot will be appended
5+
private const val snapshotBase = "0.1.0"
6+
7+
private val githubRunNumber = System.getenv("GITHUB_RUN_NUMBER")
8+
9+
private val snapshotVersion = when (githubRunNumber) {
10+
null -> "$snapshotBase-LOCAL"
11+
else -> "$snapshotBase.$githubRunNumber-SNAPSHOT"
12+
}
13+
14+
private val releaseVersion = System.getenv("RELEASE_VERSION")
15+
16+
val isRelease = releaseVersion != null
17+
val version = releaseVersion ?: snapshotVersion
18+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[versions]
22
jvm = "1.8"
3-
kotlin = "1.6.21"
3+
kotlin = "1.9.24"
44
kotlinx-coroutines = "1.6.4"
55
kotest = "5.5.5"
66
spring = "5.3.27"
77
spring-boot = "2.7.11"
88
byte-buddy = "1.14.4"
9-
skippy = "0.0.19"
9+
skippy = "0.0.20"
1010

1111
[libraries]
1212
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" }
@@ -16,6 +16,7 @@ kotest-framework-datatest = { group = "io.kotest", name = "kotest-framework-data
1616
kotest-framework-api = { group = "io.kotest", name = "kotest-framework-api", version.ref = "kotest" }
1717
kotest-property = { group = "io.kotest", name = "kotest-property", version.ref = "kotest" }
1818
kotest-runner-junit5 = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" }
19+
mockk = { group = "io.mockk", name = "mockk", version = "1.13.11" }
1920

2021
spring-context = { group = "org.springframework", name = "spring-context", version.ref = "spring" }
2122
spring-test = { group = "org.springframework", name = "spring-test", version.ref = "spring" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.kotest.extensions.skippy
2+
3+
import io.kotest.core.spec.style.FunSpec
4+
import io.kotest.matchers.string.shouldContain
5+
import org.gradle.testkit.runner.GradleRunner
6+
import java.io.File
7+
import java.io.StringWriter
8+
9+
class SkippyExtensionTest : FunSpec({
10+
// Can't seem to get Gradle to load the extension from the included build.
11+
// Keeping this around to tinker with, for now. Feel free to delete by 2025
12+
test("!Tests should execute") {
13+
val stdOut = StringWriter()
14+
15+
GradleRunner.create()
16+
.withProjectDir(File(SkippyExtensionTest::class.java.getResource("/sample-project").path))
17+
.withArguments("check", "--no-configuration-cache", "--no-build-cache")
18+
.forwardStdOutput(stdOut)
19+
.build()
20+
21+
stdOut.toString() shouldContain "SUCCESS: Executed 0 tests"
22+
}
23+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id("io.skippy") version "0.0.20"
3+
kotlin("jvm") version "1.9.24"
4+
id("com.adarshr.test-logger") version "4.0.0"
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
testImplementation("io.kotest:kotest-runner-junit5:5.9.0")
13+
testImplementation("io.kotest.extensions:kotest-extensions-skippy:0.0.1")
14+
}
15+
16+
tasks.withType<Test>().configureEach {
17+
useJUnitPlatform()
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// resources / integrationTest / src / root
2+
includeBuild("../../../../")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Foo {
2+
fun foo() = "foo"
3+
}

0 commit comments

Comments
 (0)