springboot integration principle junit

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.
Here Insert Picture Description

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.
Here Insert Picture Description

Solution

spring integrating junit idea is to rewrite the runner, in the period before the implementation of the program will load the ioc container
Here Insert Picture Description
steps:

  1. maven assembly junit (test)
  2. @Runwith comment
  3. @ContextConfigration role is to load the configuration class

@Runwith

Published 74 original articles · won praise 2 · Views 6453

Guess you like

Origin blog.csdn.net/weixin_42067668/article/details/105130148