简体   繁体   English

Kotlin类文件无法在IntelliJ for JUnit中运行

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

I am an Android and iOS developer. 我是Android和iOS开发人员。 I am new in Kotlin Programming language with IntelliJ. 我是IntelliJ的Kotlin编程语言新手。 Java class run well with but kotlin class showing err on run time. Java类运行良好,但kotlin类在运行时显示err。 First it was showing err related JUnit version. 首先,它显示了与err相关的JUnit版本。 I googled and found solution that need to config unit test. 我用谷歌搜索并找到了需要配置单元测试的解决方案。

I am using mac so I press Command + Shift + T to configure unit test. 我使用的是Mac,因此按Command + Shift + T可以配置单元测试。

After that when I run the MySecondClass.kt it's showing err like this 之后,当我运行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

My Project Structure is like this: 我的项目结构是这样的:

在此处输入图片说明

What should I do? 我该怎么办?

You probably chose the wrong testing library version in the create test dialog. 您可能在“创建测试”对话框中选择了错误的测试库版本。

在此处输入图片说明

It seems you are trying to use JUnit5, but you must have selected JUnit3. 似乎您正在尝试使用JUnit5,但是您必须选择了JUnit3。 The import for the former starts org.junit.jupiter whereas the latter starts with junit , which you see in the error that you gave in the question. 前者的导入起始于org.junit.jupiter而后者的起始于junit ,您可以在问题中输入的错误中看到。

Unresolved reference: junit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM