简体   繁体   English

在CI / CD管道中使用Maven和JUnit构建Spring Boot项目

[英]Building Spring boot Project Using Maven and JUnit in CI/CD pipeline

Here I am trying to write build stage for Jenkinsfile for making CI/CD pipeline for my spring boot project. 在这里,我试图为Jenkinsfile编写构建阶段,以为我的spring boot项目制作CI / CD管道。 When I am building the project I usually adding the mvn clean install both in my local commandline and planned to use in Jenkinsfile also. 在构建项目时,我通常会在本地命令行中添加mvn clean install,并计划在Jenkinsfile中使用它。 But later I added the JUnit as Test Driven Tool implementation and test cases with my spring boot code. 但是后来我用Spring Boot代码添加了JUnit作为测试驱动工具的实现和测试用例。 And running the each test cases by choosing Junit test from right click option of project root folder. 然后通过从项目根文件夹的右键单击选项中选择Junit测试来运行每个测试用例。

My confusion is that, when I am writing the build stage how I can build that project including JUnit test running also ? 我的困惑是,当我编写构建阶段时,如何构建包括JUnit测试运行在内的项目? Since mvn install not applying for Junit testing. 由于mvn安装未申请Junit测试。 SO How I can change project building method including Junit with Maven in project building ? 因此,如何在项目构建中更改包括Junit和Maven在内的项目构建方法?

Would anyone help me to clarify the doubt please? 有人可以帮我澄清一下疑问吗?

In order to have tests executed via Maven: 为了通过Maven执行测试:

  • include JUnit (version 4 in this case) as test dependency (copy-paste lines below in your pom.xml <dependencies> section) 包括JUnit(在这种情况下为版本4)作为测试依赖项(以下pom.xml <dependencies>部分中的复制粘贴行)

     <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> 
  • put test classes under the src/test/java folder of the Maven module 将测试类放在Maven模块的src/test/java文件夹下

  • annotate with @org.junit.Test test method cases @org.junit.Test注释测试方法案例

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM