Maven - Maven Build And Test Project - maven tutorial
maven tutorial tags : apache maven , maven repository , maven central
How to test project in Maven ?
- In previous we discuss how to create a Java application using Maven. Now we going to see how to build and test the application.
- Go to C:/MVN directory where you've created your java application. Open consumerBanking folder.You will see the POM.xml file with following contents.
learn maven tutorial - maven build command - maven example
maven tutorial tags : apache maven , maven repository , maven central
POM.xml
- Now you can see, Maven already added Junit as test framework.
- By default Maven adds a source file App.java and a test file AppTest.java in its default directory structure discussed in previous chapter.
- Let's open command console, go the C:\MVN\consumerBanking directory and execute the following mvn command.
- Maven will start building the project.
maven tutorial tags : apache maven , maven repository , maven central
Output
- You've built your project and created final jar file, following are the key learning concepts
- We give maven two goals, first to clean the target directory (clean) and then package the project build output as jar(package).
- Packaged jar is available in consumerBanking\target folder as consumerBanking-1.0-SNAPSHOT.jar.
- Test reports are available in consumerBanking\target\surefire-reports folder.
- Maven compiled source code file(s) and then test source code file(s).
- Then Maven run the test cases.
- Finally Maven created the package.
- Now open command console, go the
- C:\MVN\consumerBanking\target\classes directory and execute the following java command.
maven tutorial tags : apache maven , maven repository , maven central
Output
Adding Java Source Files
- Let's see how we can add additional Java files in our project. Open C:\MVN\consumerBanking\src\main\java\com\companyname\bank folder, create Util class in it as Util.java.
maven tutorial tags : apache maven , maven repository , maven central
Util.java
- Update App class to use Util class.
maven tutorial tags : apache maven , maven repository , maven central
Sample code
- Now open command console, go the C:\MVN\consumerBanking directory and execute the following mvn command.
- After Maven build is successful, go the C:\MVN\consumerBanking\target\classes directory and execute the following java command.
maven tutorial tags : apache maven , maven repository , maven central
Output
Automated Integration Testing with Maven
learn maven tutorial - maven project - apache maven - automated integration testing - Apache Maven example programs