簡體   English   中英

Kotlin類文件無法在IntelliJ for JUnit中運行

[英]Kotlin class file can not run in IntelliJ for JUnit

我是Android和iOS開發人員。 我是IntelliJ的Kotlin編程語言新手。 Java類運行良好,但kotlin類在運行時顯示err。 首先,它顯示了與err相關的JUnit版本。 我用谷歌搜索並找到了需要配置單元測試的解決方案。

我使用的是Mac,因此按Command + Shift + T可以配置單元測試。

之后,當我運行MySecondClass.kt時,顯示的是這樣的錯誤

Information:Kotlin: kotlinc-jvm 1.1.3-2 (JRE 1.8.0_111-b14)
Information:7/10/17, 8:24 PM - Compilation completed with 2 errors and 0 warnings in 2s 85ms
/Users/ehaque/IdeaProjects/My First Kotlin Project/src/MySecondClassTest.kt
Error:(1, 12) Kotlin: Unresolved reference: junit
Error:(7, 10) Kotlin: Unresolved reference: junit

我的項目結構是這樣的:

在此處輸入圖片說明

我該怎么辦?

您可能在“創建測試”對話框中選擇了錯誤的測試庫版本。

在此處輸入圖片說明

似乎您正在嘗試使用JUnit5,但是您必須選擇了JUnit3。 前者的導入起始於org.junit.jupiter而后者的起始於junit ,您可以在問題中輸入的錯誤中看到。

Unresolved reference: junit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM