1

I'm using this API I found online which suits exactly my purpose, but it uses its own runner and doesn't allow me to use Spring's own, which leads to plethora of problems. How do I load a context in that file?

I want to load some beans related to DAO btw, is that possible without @ContextConfiguration?

  • 1
    you could post your code that it is not working , otherwise you ll not get so helpful answers. Anyway you could wire the Context Manually in your Before Tests method like [here](https://www.mkyong.com/spring3/spring-3-hello-world-example/) – AntJavaDev Oct 04 '16 at 11:42
  • 1
    Take some time and [read the reference guide](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-junit4-rules). – M. Deinum Oct 04 '16 at 12:02
  • See http://stackoverflow.com/questions/24431427/multiple-runwith-statements-in-junit for some ideas. Particularly, seeing what this API's runner actually does - you might be able to do all its work by calling methods in @BeforeClass instead; leaving you free to use Spring's runner. Or have a look at JUnit5, which I've heard takes a different approach; effectively allowing multiple runners. – David Lavender Oct 04 '16 at 12:09

1 Answers1

1

As suggested in comments: instead of using the Spring JUnit runner, you can use JUnit 4 Rules with the @Rule / @ClassRule annotations. Awkwardly, you have to use both a class level and a method level rule, to get the full functionality:

@ClassRule
public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588