Spring BootにおけるJUnitがUnresolvedになる。
概要
現在、Kotlin + SpringBootを参考書を使用して入門中です。
そこで、参考書通りにJUnitを使用したテストコードを書き、% gradle test
を実行したところ下記のようなエラーが発生しました。ライブラリが正常にインポートされていないのは理解できています…。
自分なりに色々調べてみましたが解決せず…。
どなたか解決方法のご教授お願いいたします。
エラー内容
> Task :compileTestKotlin FAILED e: /Users/kondohiroki/IdeaProjects/demo_db/src/test/kotlin/com/example/hello_db_app/demo_db/ControllerTests.kt: (6, 18): Unresolved reference: Before e: /Users/kondohiroki/IdeaProjects/demo_db/src/test/kotlin/com/example/hello_db_app/demo_db/ControllerTests.kt: (7, 18): Unresolved reference: Test e: /Users/kondohiroki/IdeaProjects/demo_db/src/test/kotlin/com/example/hello_db_app/demo_db/ControllerTests.kt: (8, 30): Unresolved reference: Before e: /Users/kondohiroki/IdeaProjects/demo_db/src/test/kotlin/com/example/hello_db_app/demo_db/ControllerTests.kt: (10, 18): Unresolved reference: runner e: /Users/kondohiroki/IdeaProjects/demo_db/src/test/kotlin/com/example/hello_db_app/demo_db/ControllerTests.kt: (21, 2): Unresolved reference: RunWith e: /Users/kondohiroki/IdeaProjects/demo_db/src/test/kotlin/com/example/hello_db_app/demo_db/ControllerTests.kt: (30, 6): Unresolved reference: BeforeEach
該当のソースコード
Kotlin
1// ControllerTests.kt 2 3package com.example.hello_db_app.demo_db.controllers 4 5import com.example.hello_db_app.demo_db.MainController 6import com.example.hello_db_app.demo_db.User 7import org.aspectj.lang.annotation.Before 8import org.junit.Before 9import org.junit.Test 10import org.junit.jupiter.api.Before 11import org.junit.jupiter.api.Test 12import org.junit.runner.RunWith 13import org.springframework.beans.factory.annotation.Autowired 14import org.springframework.boot.test.context.SpringBootTest 15import org.springframework.http.MediaType 16import org.springframework.test.context.jdbc.Sql 17import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 18import org.springframework.test.web.servlet.MockMvc 19import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* 20import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* 21import org.springframework.test.web.servlet.setup.MockMvcBuilders 22 23@RunWith(SpringJUnit4ClassRunner::class) 24@SpringBootTest 25class ControllerTests { 26 27 テスト処理...略 28 29}
Kotlin
1// build.gradle.kts 2 3import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 4 5plugins { 6 id("org.springframework.boot") version "2.2.2.RELEASE" 7 id("io.spring.dependency-management") version "1.0.8.RELEASE" 8 kotlin("jvm") version "1.3.61" 9 kotlin("plugin.spring") version "1.3.61" 10 kotlin("plugin.jpa") version "1.3.61" 11} 12 13group = "com.example.hello_db_app" 14version = "0.0.1-SNAPSHOT" 15java.sourceCompatibility = JavaVersion.VERSION_1_8 16 17repositories { 18 mavenCentral() 19} 20 21dependencies { 22 implementation("org.springframework.boot:spring-boot-starter-data-jpa") 23 implementation("org.springframework.boot:spring-boot-starter-thymeleaf") 24 implementation("org.springframework.boot:spring-boot-starter-web") 25 implementation("com.fasterxml.jackson.module:jackson-module-kotlin") 26 implementation("org.jetbrains.kotlin:kotlin-reflect") 27 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 28 runtimeOnly("com.h2database:h2") 29 testImplementation("org.springframework.boot:spring-boot-starter-test") { 30 exclude(group = "org.junit.vintage", module = "junit-vintage-engine") 31 } 32} 33 34tasks.withType<Test> { 35 useJUnitPlatform() 36} 37 38tasks.withType<KotlinCompile> { 39 kotlinOptions { 40 freeCompilerArgs = listOf("-Xjsr305=strict") 41 jvmTarget = "1.8" 42 } 43} 44
回答1件
あなたの回答
tips
プレビュー