Skip to content

Commit

Permalink
replace dynatest with junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Aug 18, 2024
1 parent 0bbae47 commit 4cdbbfb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {

// test support
testImplementation(libs.karibu.testing)
testImplementation(libs.dynatest)
testRuntimeOnly(libs.junit.platform.launcher)
testImplementation(libs.junit)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.withType<KotlinCompile> {
Expand Down
7 changes: 3 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[versions]
vaadin = "24.4.7"
vaadin = "24.4.8"
# https://repo1.maven.org/maven2/org/slf4j/slf4j-api/
slf4j = "2.0.13"

[libraries]
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
vaadin-boot = "com.github.mvysny.vaadin-boot:vaadin-boot:12.2"
vaadin-boot = "com.github.mvysny.vaadin-boot:vaadin-boot:12.3"
vaadin-core = { module = "com.vaadin:vaadin-core", version.ref = "vaadin" }
karibu-testing = "com.github.mvysny.kaributesting:karibu-testing-v24:2.1.8"
karibu-dsl = "com.github.mvysny.karibudsl:karibu-dsl-v23:2.1.3"
junit-platform-launcher = "org.junit.platform:junit-platform-launcher:1.10.2"
dynatest = "com.github.mvysny.dynatest:dynatest:0.25"
junit = "org.junit.jupiter:junit-jupiter-engine:5.11.0"

[plugins]
vaadin = { id = "com.vaadin", version.ref = "vaadin" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
31 changes: 18 additions & 13 deletions src/test/kotlin/com/example/karibudsl/MainViewTest.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package com.example.karibudsl

import com.github.mvysny.kaributesting.v10.*
import com.github.mvysny.dynatest.DynaTest
import com.vaadin.flow.component.UI
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.textfield.TextField
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

/**
* Tests the UI. Uses the Browserless testing approach as provided by the
* [Karibu Testing](https://github.com/mvysny/karibu-testing) library.
*/
class MainViewTest: DynaTest({
lateinit var routes: Routes
beforeGroup {
// Route discovery involves classpath scanning and is an expensive operation.
// Running the discovery process only once per test run speeds up the test runtime considerably.
// Discover the routes once and cache the result.
routes = Routes().autoDiscoverViews("com.example.karibudsl")
class MainViewTest {
companion object {
private lateinit var routes: Routes
@BeforeAll @JvmStatic fun discoverRoutes() {
// Route discovery involves classpath scanning and is an expensive operation.
// Running the discovery process only once per test run speeds up the test runtime considerably.
// Discover the routes once and cache the result.
routes = Routes().autoDiscoverViews("com.example.karibudsl")
}
}
beforeEach {
@BeforeEach fun setupVaadin() {
// MockVaadin.setup() registers all @Routes, prepares the Vaadin instances for us
// (the UI, the VaadinSession, VaadinRequest, VaadinResponse, ...) and navigates to the root route.
MockVaadin.setup(routes)
}
afterEach { MockVaadin.tearDown() }
@AfterEach fun teardownVaadin() { MockVaadin.tearDown() }

test("smoke test") {
@Test fun smokeTest() {
// Smoke test is a quick test to check that the basic machinery is in place and works.
// The analogy would be to turn on an electric device (e.g. a coffee maker)
// then turn it off immediately without even checking whether it actually works or not,
Expand All @@ -43,7 +48,7 @@ class MainViewTest: DynaTest({
_expectOne<MainView>()
}

test("test greeting") {
@Test fun testGreeting() {
// simulate an user input
_get<TextField> { label = "Your name" } ._value = "Martin"

Expand All @@ -53,4 +58,4 @@ class MainViewTest: DynaTest({
// look up the notification and assert on its value
expectNotifications("Hello, Martin")
}
})
}

0 comments on commit 4cdbbfb

Please sign in to comment.