dimanche 28 juin 2015

Junit 4 + Eclipse - Run inner class test cases with SpringJUnit4ClassRunner as well

I need to run inner class test cases from eclipse using Junit4. I understand that there is org.junit.runners.Enclosed that is intended to serve this purpose. It works well for "plain" unit test i.e. without the need for spring context configuration.

For my case, give sample code below, Adding another annotation of Enclosed does not work since there is a conflict of both SpringJUnit4ClassRunner and Enclosed test runners. How can I solve this problem ?

Note: Kindly ignore any basic spelling mistake/basic import issues in the below example since I tried to cook up from my actual use-case.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/unit-test-context.xml"})
public class FooUnitTest {

// Mocked dependency through spring context 
@Inject
protected DependentService dependentService;

 public static class FooBasicScenarios extends FooUnitTest{
   @Test
   public void testCase1 {
   .....
   List<Data> data = dependentService.getData();
    .....
   }
  }


 public static class FooNeagativeScenarios extends FooUnitTest{
   @Test
   public void testCase1 {
   .....
   List<Data> data = dependentService.getData();
    .....
   }
  }
} 


}

Aucun commentaire:

Enregistrer un commentaire