Posts

Showing posts with the label junit

JUnit Easymock - spurious results invoking unit test method as a) method b) within class c) as mvn build

JUnit Easymock - spurious results invoking unit test method as a) method b) within class c) as mvn build I have a unit test and contained within this unit test is my problem method: @Test(expected = CheckoutException.class) public void performCheckout_CheckoutException() throws Exception { // setup test data Order order = new OrderImpl(); OMSOrder omsOrder = new OMSOrderImpl(); Order omsOrderProxy = OMSOrderProxy.proxify(order, omsOrder, Logger.getRootLogger()); omsOrderProxy.setId(1L); FulfillmentOrder fulfillmentOrder = new FulfillmentOrderImpl(); FulfillmentGroup fulfillmentGroup = new FulfillmentGroupImpl(); fulfillmentGroup.setType(FulfillmentType.DIGITAL); fulfillmentOrder.setFulfillmentGroup(fulfillmentGroup); ((OMSOrder)omsOrderProxy).getAllFulfillmentOrders().add(fulfillmentOrder); ProcessContext<CheckoutSeed> context = new DefaultProcessContextImpl<>(); // create the expected flow expect(orderService.save(anyObje...

Spring MockMvc WebApplicationContext is null when running JUnit Tests with Maven

Spring MockMvc WebApplicationContext is null when running JUnit Tests with Maven I have a Spring mock-mvc JUnit test class that contains two tests. When I run the tests within Eclipse IDE both tests pass (I use Eclipse Maven plugin). When running the tests from the command line using mvn test one of the tests fails because the WebApplicationContext that is @Autowired is sometimes null. Here is my test class @WebAppConfiguration @ActiveProfiles({ "dev", "test" }) public class AddLinkEndpointMvcTest extends BaseMvc { @Autowired private WebApplicationContext wac; private MockMvc mockMvc; @Before public void before() { System.out.println("WAC = " + wac); mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } @Test public void addLinkDoesNotSupportGet() throws Exception { mockMvc.perform(get("/myurl")).andExpect(status().is(HttpStatus.SC_METHOD_NOT_ALLOWED)); } @Test public v...