How does IntelliJ figure out where the tests are and which ones to run?
When I use sbt test from the UNIX command line at the project top level directory, all my tests run. But interactively in IntelliJ they don’t, in fact IntelliJ doesn’t find any tests unless I point the mouse to the actutal file containing the tests.
If I point the mouse to the GreetingTestSuite file in the file browser, I can run GreetingTestSuite, and it runs correctly.
This may be a bug, but I have an idea what may cause it. Look at the folder icons in this screenshot:
lecture-1 to 4 use this one which is for simple folders, while other and projects use this one , which signifies a package.
This looks to me like Intellij does enforce folder names to be valid package names (which aren’t allowed to contain -), although Scala doesn’t require that. Maybe that causes it to not look in these folders?
It’s a reasonable guess that the - in the file name is confusing IntelliJ, but alas it doesn’t seem to be the case. If I change the directory name to lecture1 without the -, it still cannot find any tests. IntelliJ seems to search for tests in the package named lecture rather than in the directory named lecture1.
I fully realize my opinion is a minority opinion. But I really don’t like the idea that package name needs to match the directory hierarchy.
When I eliminate the lecture-1 through lecture-4 directories the tests all run. But now it will probably be difficult for students to figure out which test file corresponds to which homework assignment.
The green color means it’s a test source root. Children will all be searched for tests if they’re not excluded.
The problem stems from hyphens not being valid characters in package names. IntelliJ will create such a package for you, but things start breaking after that.
In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen…
It seems like this is an IntelliJ bug. I removed the entire work area from disk, and re-cloned from git. In the git repo, I don’t have any of the the InteliJ cache files or compiled libraries–just the source code. After the re-clone finished, I can now run all the tests.