Using the spring framework to make it easy to write code with separate tests for some code snippet code without having to run the entire environment for testing, the JUnit test is introduced to facilitate the testing of the local code block.
1, first guide package, such as MAVEN project: where JUnit needs at least in the 4.12 version, or will be error
2 Create a new test package and set the test package to test Source Root
3, the new class plus annotations, load the test class, load the spring configuration file, because spring Auto-injection helps us inject the image, so it can be obtained directly through annotations when used, but the spring configuration file should have the declaration of the relevant Bean object, in order to inject the use in the test.
4, you can test directly in the class, you can also let the subclass inherit the class, the subclass inherits, then does not need the annotation introduction context.
Using JUnit Test in the spring environment