gjw80
gjw80

Reputation: 1078

How do I test a class using JUnit 4 that extends an abstract class?

I am trying to write a unit test for a java class that is extending an abstract class? The java class looks sort of like:

public class XYZFilter extends XYZDataFilter{

   @Override
   protected boolean filterItem(Model d, String sector) {

    //method code
    return true;    
   }
}

The junit test class looks like:

import org.junit.Test;
import static org.junit.Assert.assertTrue;

public class XYZFilterTest {
Model m = new Model();
String sector = "SECTOR";

@Test
public void testFilterItem() throws Exception {

    System.out.println("\nTest filterItem method...");
    XYZFilter f = new XYZFilter();
    assertTrue(f.filterItem(m, sector));
}
}   

So I'm having a problem with the abstract DataFilter which is extended by the Filter class, as well as the Model class. I believe I need to mock these objects using JMockit but I am having a lot of trouble figuring out how to do this. Any advice is appreciated.

Upvotes: 0

Views: 381

Answers (1)

gjw80
gjw80

Reputation: 1078

The answer is I needed to have the libraries included, JMockit doesn't handle objects in that way.

Upvotes: 1

Related Questions