2017-07-05 17 views
7

Tôi rất mới sử dụng spek trong Kotlin thử nghiệm. Khi sử dụng spek, có lỗi sau trên logcat. Tôi không lý do tại sao tôi nhận nàyjava.lang.ClassNotFoundException: com.intellij.junit5.JUnit5IdeaTestRunner sử dụng spek trong Kotlin

java.lang.ClassNotFoundException: com.intellij.junit5.JUnit5IdeaTestRunner 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:264) 
    at com.intellij.rt.execution.junit.JUnitStarter.getAgentClass(JUnitStarter.java:252) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131) 

tôi đã phụ thuộc vào tập tin gradle sau

testImplementation 'junit:junit:4.12' 
testImplementation 'org.jetbrains.spek:spek-api:1.1.0-beta3' 
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.0-beta3' 
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M3' 

tập tin thử nghiệm

import org.jetbrains.spek.api.Spek 
import org.jetbrains.spek.api.dsl.given 
import org.jetbrains.spek.api.dsl.it 
import org.junit.Assert.assertEquals 
import org.junit.platform.runner.JUnitPlatform 
import org.junit.runner.RunWith 

@RunWith(JUnitPlatform::class) 
class ExampleUnitTest : Spek({ 
    val x = 2 
    val y = 3 

    given("x = $x and y = $y") { 
     val sum = x + y 

     it("should be that x + y = 5") { 
      assertEquals(5, sum) 
     } 

     it("should be that x - y = -1") { 
      val subtract = x - y 
      assertEquals(-1, subtract) 
     } 

    } 
}) 

Bạn có thể xin đề nghị, làm thế nào để có được loại hình báo lỗi . Tôi sẽ appericate đề xuất có giá trị của bạn hoặc ý kiến ​​về chủ đề này.

+0

hi, có lẽ đây là hữu ích cho bạn: http://spekframework.org/docs/latest/#_android –

Trả lời

9

Bạn chỉ cần thêm thư viện, trong đó có các Á hậu (xem thêm http://junit.org/junit5/docs/current/user-guide/#installation)

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M3' 

tôi cũng khuyến khích bạn cập nhật spek-libs của bạn lên phiên bản mới nhất:

testImplementation 'junit:junit:4.12' 
testImplementation 'org.jetbrains.spek:spek-api:1.1.2' 
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2' 
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M5' 
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M5' 

Cập nhật

Hiện tại, libit mới nhất không tương thích với whte M5-Milestone, vì vậy hãy sử dụng phiên bản M4

testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M4' 
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M4' 
+0

Cám ơn tiết kiệm thời gian của tôi, kiểm tra dường như trôi qua thành công, nhưng tôi có một số cảnh báo: * * CẢNH BÁO: TestEngine có ID 'junit-jupiter' không phát hiện được thử nghiệm ** và ** CẢNH BÁO: TestEngine có ID 'junit-jupiter' không phát hiện được các thử nghiệm ** dù sao lại cảm ơn. –

+1

Tôi đã cập nhật cho bạn mô tả ở trên. Nếu bạn hạ thấp phiên bản từ M5 xuống M4, nó hoạt động. – guenhter

+0

@guenhter THANK YOU !! – w3bshark

Các vấn đề liên quan