Problem Description:
junit use cases are used for testers, but should be noted that junit will not take the initiative and Spring ioc hook, junit only concern @test notes, and then only care about running inside, so when performing unit tests, we need to xml carried out every form of notes or ioc introduced, this will result in redundancy code.
Solutions
One thing to note: we usually must have a method of execution is the main method of entrance, but no main method junit, how is it performed?
The reason is that @Test annotation, there runner method, a boot program execution.
Solution
spring integrating junit idea is to rewrite the runner, in the period before the implementation of the program will load the ioc container
steps:
- maven assembly junit (test)
- @Runwith comment
- @ContextConfigration role is to load the configuration class
@Runwith