Java 在Scala上进行单元测试时未找到测试类

Java 在Scala上进行单元测试时未找到测试类,java,scala,unit-testing,intellij-idea,Java,Scala,Unit Testing,Intellij Idea,我试图在Scala上运行以下单元测试。找不到错误测试类:mainFolder.TestDictionary 以下是我的目录的外观: src |_ mainFolder | |_ Dictionary.scala |_ testing |_ TestDictionary.scala 这是我的TestDictionary.scala单元测试代码 package testing import org.scalatest._ import mainFolder.D

我试图在Scala上运行以下单元测试。找不到错误测试类:mainFolder.TestDictionary

以下是我的目录的外观:

src
  |_ mainFolder
  |     |_ Dictionary.scala
  |_ testing
        |_ TestDictionary.scala
这是我的
TestDictionary.scala
单元测试代码

package testing

import org.scalatest._
import mainFolder.Dictionary

class TestDictionary extends FunSuite {
test("Use many test cases for many category"){
    val test1 = "CAT"
    val test2 = "BAT"
    val test3 = "DIAMOND"
    val test4 = "THOUSAND"
    val test5 = ""
    val test6 = "HALF"
    val test7 = "PHOTOGRAPH"
    val test8 = "STAFF"

    assert(Dictionary.isSounds(test1, test2) == true)
    assert(Dictionary.isSounds(test5, test7) == true)
    assert(Dictionary.isSounds(test4, test5) == true)
    assert(Dictionary.isSounds(test5, test8) == true)
    assert(Dictionary.isSounds(test3, test2) == true)
    assert(Dictionary.isSounds(test4, test1) == true)
    assert(Dictionary.isSounds(test1, test8) == true)
    assert(Dictionary.isSounds(test8, test3) == true)
    assert(Dictionary.isSounds(test5, test6) == true)
    assert(Dictionary.isSounds(test8, test2) == true)
}
}

我想你错过了:

 import mainFolder.Dictionary._
这将加载Dictionary.scala中的所有函数

此外,我不确定命名是否重要,但通常文件夹结构是:

src->main


src->test

您可以在Intellij中尝试三种可能的解决方案

  • 右键单击测试文件夹并选择“
    将目录标记为
    ”,然后在该“
    测试源根目录下
    ”。这是在找不到测试用例的情况下发生的最常见的事情

  • 您还可以尝试再次清理和编译代码。Try命令
    sbt clean compile

  • 即使这不起作用,也只需通过
    sbt test
    从命令行运行一次测试用例。这将帮助我们弄清楚这是否是一个intellij索引问题。如果测试用例从命令行运行,那么在intellij中可能会出现索引问题,您可以右键单击项目并
    重建项目。


  • 我使用IntellijBy的方式,导入mainFolder.Dictionary.\u不正确。