Lars
Lars

Reputation: 340

Maven will not execute tests

I have a default Maven directory structure, but it will not see/run my tests. The directory structure is as followed:

src
    -main
        -java
            -com.foo.webservice
                -...
    -test
        -java
            -com.foo.webservice
                -AbstractTest.java

When I run the command mvn test, it tells me nothing, but a successful build.

The project is viewable on my Git over here.

This is my test class:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public abstract class AbstractTest {

    @Autowired
    private CustomerDAO dao;

    @Test
    public void testGetCustomer() {
        Customer customer = new Customer();
        customer.setUsername("JUnitCustomer");
        customer.setCompanyName("SpringTest");
        customer.setPhoneNumber("0612345678");
        if (customer != null) {
            assertNotNull("Username isn't null", customer.getUsername());
            assertNotNull("Company isn't null", customer.getCompanyName());
            assertTrue(customer.getPhoneNumber().length() == 8);
        }
    }

    @Test
    public void testGetCustomerPhoneNumber() {
        assertTrue(dao.getCustomer(0).getPhoneNumber().length() == 8);
    }
}

Upvotes: 1

Views: 95

Answers (1)

Tunaki
Tunaki

Reputation: 137064

By looking at your code, the class you want to test with JUnit is abstract.

However, for JUnit to run your test, your class must not be abstract. You should declare your class like this:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class MyTest {

    @Test
    public void testSomething() {
    }

}

Upvotes: 2

Related Questions