0

Here I am trying to write build stage for Jenkinsfile for making CI/CD pipeline for my spring boot project. 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. But later I added the JUnit as Test Driven Tool implementation and test cases with my spring boot code. And running the each test cases by choosing Junit test from right click option of project root folder.

My confusion is that, when I am writing the build stage how I can build that project including JUnit test running also ? Since mvn install not applying for Junit testing. SO How I can change project building method including Junit with Maven in project building ?

Would anyone help me to clarify the doubt please?

Mr.DevEng
  • 2,651
  • 14
  • 57
  • 115

1 Answers1

1

In order to have tests executed via Maven:

  • include JUnit (version 4 in this case) as test dependency (copy-paste lines below in your pom.xml <dependencies> section)

    <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

  • annotate with @org.junit.Test test method cases

References:

  • Yaa.. I understood that. But my confusion is that does test cases run when I use "mvn install" in my pipeline stage ? Now I am running each test cases by right clicking run with Junit option. So I felt doubt that does test cases work If I use mvn install ? This is my confusion. Can you clarify please ? And Thank you for your response. – Mr.DevEng Aug 22 '18 at 06:28
  • Yes, it should. In order to be sure, you could simply write a failing test (`assertTrue(false)` should do the trick) and execute `mvn clean install` from your local terminal. If the build fails as expected, you're ok. – Giancarlo Di Paolantonio Aug 22 '18 at 10:42