Anonymous
Anonymous

Reputation: 87

Test Class Not Found when Unit Testing on Scala

I am trying to run the following Unit Test on Scala. I am getting error test class not found: mainFolder.TestDictionary

Here is what my directory looks like:

src
  |_ mainFolder
  |     |_ Dictionary.scala
  |_ testing
        |_ TestDictionary.scala

Here is my TestDictionary.scala Unit Testing Code

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)
}
}

Upvotes: 2

Views: 3238

Answers (2)

Chaitanya
Chaitanya

Reputation: 3638

There are three possible solutions which you could try in Intellij

  1. Right click on the test folder and select 'Mark directory as' and in that 'Test Sources Root'. This is the most common thing that happens in case of test case not found.

  2. Also you could try cleaning and compiling your code again. Try command sbt clean compile

  3. Even if this does not work, just try once to run the test cases from command line by sbt test. This will help us figure out if it is an intellij indexing issue. If the test cases run from command line, then it might be an indexing issue in intellij and you can right click on your project and Rebuild Project.

Upvotes: 1

user3674993
user3674993

Reputation: 129

I think you are missing:

 import mainFolder.Dictionary._

This should load all the functions in the Dictionary.scala

Also I am not sure if the naming matters but generally the folder structure is:

src -> main

src -> test

Upvotes: 1

Related Questions