1

I am running into an issue while mocking the autowired component of a mvc controller. Here is my code, I am on Jmockit 1.28

@RunWith(SpringJUnit4ClassRunner.class)
@WebMvcTest(value = SomeController.class, secure = false)

public class SomeControllerUTest {


   @BeforeClass
   public static void applySpringIntegration() {
      new BeanFactoryMockUp();
   }

@Before
public void setup() throws Exception {
    mockMvc = MockMvcBuilders.standaloneSetup(someController).build();

}
MockMvc mockMvc;

@Injectable
private DepServiceImpl depService;

@Tested(availableDuringSetup = true,fullyInitialized = true)
private SomeController someController;


@Test
public void testSomeBehavior() throws Exception {

     BeanFactory beanFactory = new DefaultListableBeanFactory();
     DepService service = (DepServiceImpl) beanFactory.getBean("depService");


    assertSame(mlService, service);



}
}

Seeing the following error while running mvn test

Tests in error: com.test.SomeControllerUTest: Unable to find class file for org.springframework.beans.factory.support.$Subclass_AbstractBeanFactory

LMC
  • 10,453
  • 2
  • 27
  • 52
user3221430
  • 71
  • 1
  • 6
  • Missing test dependency perhaps? – Phil Jun 11 '18 at 23:06
  • I doubt it, it seems to be related to the @BeforeClass instantiating BeanFactoryMockUp(). But thats as per http://jmockit.github.io/tutorial/EnterpriseApplications.html#spring – user3221430 Jun 12 '18 at 00:04

0 Answers0