1

I've been trying to get tests with code coverage to work in IntelliJ for a couple of hours so far, without success.

First off: "Run with coverage>" without junit included in the project produces the following error (obviously)

Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter

Adding junit 4.11 and hamcrest-core 1.3 to libraries, then "run with coverage":

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!

Now, I have read that changing the dependency order in the module options fixes this. So after changing the order, I get this error:

junit.framework.AssertionFailedError: Exception in constructor: testMakeTextView (java.lang.NoClassDefFoundError: be/dave/DiversoScoreApp/MyActivity
at be.dave.DiversoScoreApp.MyActivityTest.<init>(MyActivityTest.java:20)

Which points to the code below:

public class MyActivityTest extends ActivityInstrumentationTestCase2<MyActivity> {
MyActivity myActivity;

public MyActivityTest() {
    super("be.dave.DiversoScoreApp", MyActivity.class);
}

@Override
public void setUp() throws Exception {
    super.setUp();
    myActivity = getActivity();
}

public void testMakeTextView() throws Exception {
    TextView textView = myActivity.makeTextView("Test-text", 50);
    TextView textView1 = myActivity.makeTextView("Diverso", 75);
    assertEquals("TextView Text should be correct", textView.getText(), "Test-text");
    assertNotSame("TextView Text should fail", textView1.getText(), "Not Diverso");
    } 
}

I've googled and googled, but alas I've found no solution so far.

Community
  • 1
  • 1
Dave DV
  • 13
  • 2

1 Answers1

0

If you are trying to test the testMakeTextView method you should annotate it with the @Test symbol. So

@Test
public void testMakeTextView()

Also the setUp() method has a @Before annotation rather than the @Override i think.

user2511882
  • 9,022
  • 10
  • 51
  • 59
  • I changed both to your suggestions, but sadly the NoClassDefFoundError remains – Dave DV Dec 01 '13 at 21:53
  • Did you add hamcrest to the runtime path? – user2511882 Dec 01 '13 at 22:22
  • I've added both JUnit and hamcrest to the libraries of the project, if that is what you mean? – Dave DV Dec 02 '13 at 13:45
  • Here, try this and see if it works: http://stackoverflow.com/questions/8678630/noclassdeffounderror-android – user2511882 Dec 02 '13 at 14:14
  • I'm afraid the options stated there are not available in IntelliJ, the only things I found are the "src" and "gen" source folders and they are in the order the answer specifies. (http://d.pr/i/Ea4l) Either that or I'm being completely blind... – Dave DV Dec 02 '13 at 14:45
  • Are you building using maven? If so make sure that scope on the hamcrest plugin is test and not provided – user2511882 Dec 02 '13 at 14:55
  • No, just a regular android project in IntelliJ, so I've manually added the jars to the project. – Dave DV Dec 02 '13 at 15:26
  • I am not sure. All i can tell you is that the classDefError on the AssertThat generally means that it cannot see the hamcrest lib during runtime. It compiles with it fine, but during runtime somehow it fails to find the hamcrest library. Look around and see if any imports are messed up. And upvote if you found anything helpful. Cheers! – user2511882 Dec 02 '13 at 16:03
  • I'll try to fix it using maven next, I'll upvote already since you've been very helpful, thanks! EDIT: I *tried* upvoting but I need more reputation apparantly... – Dave DV Dec 02 '13 at 16:27