Search code examples
javajmockjunit3

The type junit.framework.TestCase cannot be resolved. It is indirectly referenced from required .class files


I'm following the example here: jMock - getting started

I'm getting this error: The type junit.framework.TestCase cannot be resolved. It is indirectly referenced from required .class files

I've imported these 4 jars:

  • jmock-2.5.1.jar
  • hamcrest-core-1.1.jar
  • hamcrest-library-1.1.jar
  • jmock-junit3-2.5.1.jar

Ant ideas of what this error means?

package com.test;

import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;

class PublisherTest extends MockObjectTestCase {
public void testOneSubscriberReceivesAMessage() {
    // set up
    final Subscriber subscriber = mock(Subscriber.class);

    Publisher publisher = new Publisher();
    publisher.add(subscriber);

    final String message = "message";

    // expectations
    checking(new Expectations() {
        {
            oneOf(subscriber).receive(message);
        }
    });

    // execute
    publisher.publish(message);
    }
}

Solution

  • Add JUnit 3 to your classpath.