Duration: 1 Day
Installing the Maven
- Download the latest version of Maven and Install by unzipping the war file
- Create an environment variable MAVEN_HOME
- Add the path for Maven. Path is always set to bin
- Check the maven is properly configured using the command mvn –version
Installing the M2Eclipse Plugin
- Select Help | Install New Software from Eclipse Menu
- Add a new repository named M2Eclipse for the URL: http://download.eclipse.org/technology/m2e/releases
- Select the plugins and Install. Apache maven is integrated to the IDE
- Check if maven has been installed successfully
- Click Help-> About Eclipse and then check the presence of M2Eclipse icon
- Get the details of the Maven installation by clicking on the M2Eclipse icon
Creating the Maven Project
- Create a new Project from File-> New->Other, then Select Maven -> Maven Project
- Select the Create a simple project while creating the Maven project
- Group Id: com.jala.maven
- Artifact id: MavenTest
- Check the project structure
- By default, the JRE System library is pointing to J2SE1.5. Change it default JRE on your system (latest JRE on your system)
- Select pom.xml from Project explorer
- Add dependencies for TestNG, maven, Selenium and log4J with in the project node
- Maven dependencies
- Know the path where the dependency jars are downloaded to from central repository of maven(.m2 folder in users->username)
- Create a TestNG class in src/test/java by right clicking on the folder with all the annotations selected and name it FirstTest.
Add print statements for every annotation to check the order of the annotations execution
- System.out.println("Before Suite");
- System.out.println("After Suite");
- Add a first test case with the annotation @Test and name it firstTestCase
- Run the TestNG test case and observe the order of the annotations execution
- Convert the Maven project to TestNG Project by right clicking on the project and then click TestNG->Convert to TestNG
testng.xml file is generated in the project folder
- Running test from testing.xml
Right click on testing.xml, Run As -> Run configurations
Type testing.xml for Suite, So it runs testing.xml file when the test suite is run
Then continue running the test suite from testing.xml by right clicking on xml file
Running the test as Maven Test
- Add dependencies for
- Run test as maven test
Right Click on the project and Run As->Maven test
(Run Maven clean, Maven Build and then Maven test if script fails)
Default Life Cycle
The default life cycle is the build life cycle which generates, compiles, packages etc. your source code
You cannot execute the default build life cycle directly, as is possible with the clean and site. Instead you have to execute a specific build phase within the default build life cycle
The most commonly used build phases in the default build life cycle are:
Build Phase: Description.
validate: Validates that the project is correct and all necessary information is available.This also makes sure the dependencies are downloaded.
compile: Compiles the source code of the project.
test: Runs the tests against the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
package: Packs the compiled code in its distributable format, such as a JAR.
install: Install the package into the local repository, for use as a dependency in other proje-cts locally.
deploy: Copies the final package to the remote repository for sharing with other developers and projects.