如何在java中为一个接口和多个实现类实现junit

时间:2016-10-05 06:52:26

标签: java junit

我有一个接口(Clause.java)和两个实现类(OrderClause.java和GroupClause.java) 我无法创建Clause.java类的实例 请参阅我的ClauseTest类示例:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:config/applicationContextList.xml")
public class ClauseTest {

    public ClauseTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of getQueryString method, of class Clause.
     */
    @Test
    public void testGetQueryString() {
        System.out.println("getQueryString");
        Clause instance = new ClauseImpl();
        String expResult = "";
        String result = instance.getQueryString();
        assertEquals(expResult, result);
        fail("The test case is a prototype.");
    }

1 个答案:

答案 0 :(得分:1)

你写的是Clause是一个接口,而不是类。您无法直接实例化界面。您需要创建实现该接口的类的实例:

Clause instance = new OrderClause();