4

I'm getting below error while unit testing-

    Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

Project structure is- enter image description here

After some investigation in Run Configuration came to know its taking wrong module(main.java.com.example.dexter.sunshine.app) while running this unit case. How can we change this module?

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
Vikram
  • 768
  • 2
  • 9
  • 23
  • possible duplicate of [Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter](http://stackoverflow.com/questions/19516289/exception-in-thread-main-java-lang-noclassdeffounderror-junit-textui-resultpr) – Divers May 17 '15 at 18:00

2 Answers2

5

I had a similar issue trying to run a groovy test suite.

Try right clicking the java directory under src/androidTest/java and choosing mark directory as -> test sources root

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • Excellent. I would add, that we should use the *mark directory as source root* command, too, for the root of the tested files. http://stackoverflow.com/a/36057080/715269. – Gangnus Mar 17 '16 at 10:08
4

I had the same problem and had to look for this for a little bit, and here is what I found.

Go to Run -> Edit Configuration ... to open Run/Debug Configurations.

From there you can either modify your current configurations (whether for JUnit, Android Tests, or Android Application), or you can add a new one as you need. I am sure you can change the class name there.

m.hashemian
  • 1,786
  • 2
  • 15
  • 31