SpringBoot hot deployment and unit testing
preface
We use SpringBoot in the process of development there are two very practical ways to help us improve the efficiency of development, respectively is SpringBoot hot deployment and unit testing, this blog will simply use these two ways, do a brief introduction.
The body of the
SpringBoot hot deployment
SpringBoot with spring-boot-DevTools, you can automatically restart and deploy projects when changing program code, greatly improving the speed of development and debugging.
IDEA Modifies two parameters:
CTRL + SHIFT + A
— > lookupmake project automatically
— > selectedCtrl + Shift +A
Find the samecomplier.automake.allow.when.app.running
, click the check box.
In Chrome, press F12 to turn off the cache
Add the following code to pom.xml
<! <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional>
<scope>true</scope> </dependency> <! <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
Copy the code
After we modify the code after the above configuration, IDEA will help us repackage and run the project.
Unit testing
Method 1: Start SpringBoot with the boot class and load the default application.properties
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = App.class)
public class AppForTest {
@Test
public void ceshi(a){}}Copy the code
Method 2: @contextConfiguration Specifies the configuration file
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/application-test.xml")
public class AppForTest {
@Test
public void ceshi(a){}}Copy the code
Note the following additions to pom.xml when using unit tests
- Packaging will be
test
Part of the ruled out - Configure the path to the formal and tested resource files
<build> <finalName>${project.artifactId}-${project.version}</finalName> <plugins> <! Plugins </groupId> <artifactId> Maven-surefire-plugin </artifactId> <configuration> <includes> <include>**/Test.java</include> </includes> <excludes> <exclude>**/TestCase.java</exclude> </excludes> <skip>false</skip>
<testFailureIgnore>false</testFailureIgnore> </configuration> </plugin> </plugins> <! -- Resource file --> <resources> <resource> <directory> SRC /main/resources</directory> <includes> **/*</include> </includes> </resource> </resources> <! <testResources> <testResource> <directory> SRC /test/resources</directory> </testResource> <! --<testResource>--> <! --<directory>src/main/resources</directory>--> <! --</testResource>--> </testResources> </build>Copy the code