简体   繁体   中英

Kotlin class file can not run in IntelliJ for JUnit

I am an Android and iOS developer. I am new in Kotlin Programming language with IntelliJ. Java class run well with but kotlin class showing err on run time. First it was showing err related JUnit version. 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.

After that when I run the MySecondClass.kt it's showing err like this

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. 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.

Unresolved reference: junit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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