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?

3
  • 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 Commented Oct 4, 2016 at 11:42
  • 1
    Take some time and read the reference guide. Commented Oct 4, 2016 at 12:02
  • See stackoverflow.com/questions/24431427/… 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. Commented Oct 4, 2016 at 12:09

1 Answer 1

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(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.