Running tests on Intellij: Class not found

2019-01-23 10:47发布

I'm evaluating IntelliJ (13.0.2 133.696) and cannot get jUnit tests to run from within the IDE.

My project is a multi module gradle project and uses scala.

Test class is located under src/test/scala/xxx/xxxxx/xxx/xxxx/xxxxx and everytime i try to run from IDE i get the same error:

Class not found: "xxx.xxxxx.xxx.xxxx.xxxxx.AccountRepositoryTest"

Test class is nothing fancy, simple jUnit test:

@RunWith(classOf[SpringJUnit4ClassRunner])
@ContextConfiguration(classes = Array(classOf[DataConfig], classOf[SettingsConfig]))
class AccountRepositoryTest extends AssertionsForJUnit {

I've found a related question Cannot run Junit tests from IDEA 13.0 IDE for imported gradle projects , but the provided fix (upgrade to 13.0.2) does not work.

I've even tried upgrading to the latest EAP, still the same issue.

9条回答
倾城 Initia
2楼-- · 2019-01-23 11:16

I had the same problem. I changed a path in Module Settings -> Modules -> Paths -> Test output path to my directory for test classes bytecode (exclude output paths on). Now everything works!

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-23 11:25

You can try to invalidate the cache and restart. That usually will resolve issues when you add new dependencies / classes.

查看更多
时光不老,我们不散
4楼-- · 2019-01-23 11:28

Go to Project Settings -> Project.

Fill in Project compiler output: ex. D:\repo\Project\out

Go to Module -> Paths

Make sure that:

output path is like D:\repo\Project\out\production

test output path like D:\repo\Project\out\test

Should work!

查看更多
登录 后发表回答