Maven Interview Questions
- What is the usage of sure-fire plug-in in pom.xml ?
- How do you run cucumber tags on mvn command line ?
2. Explain the directory structure of a Maven project.
3. What is a POM in Maven?
4. What is the purpose of the settings.xml file in Maven?
5. Explain the Maven build lifecycle.
6. What is a Maven artifact?
7. Explain the difference between compile, test, and runtime scopes in Maven.
8. What is the purpose of the dependencyManagement section in a Maven POM?
9. What is the purpose of the mvn clean install command?
10. Explain the role of profiles in Maven.
1. What is the usage of sure-fire plug-in in pom.xml ?
Maven-surefire-plugin: Surefire-plugin is responsible for running tests that are placed in test source directory /src/test/java.<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
By default, Surefire-plugin runs all tests that matches with filename pattern such as *Test.java in test source directory src/test/java .
To use a different naming scheme, we can configure Surefire Plugin which includes parameter and specify the tests that we want to include
To use a different naming scheme, we can configure Surefire Plugin which includes parameter and specify the tests that we want to include
How do you run cucumber tags on mvn command line ?
First, we configure testng.xml file in maven sure-fire-plugin in the pom.xml file under plug-ins section.Then we use mvn test or mvn test -Dcucumber.filter.tags="@tag"
For instance, let's take below tags used for 4 scenarios in 2 feature files.
//tags="@LoginValidCredentials",
//tags="@DashboardTabCountOfQuickLaunhElements",
//tags="@DirectoryTabNavigationFromDashboardTab",
//tags="@DirectoryTabIsSearchButtonDisplayed",
Below command by default runs all the scenarios, basically irrespective of what we specify in CucumberOptions in the runner class maven will override it and run all the scenarios.
mvn test
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
To run all the scenarios by mentionting all the tags, we need to use or between scenarios.
mvn test -Dcucumber.filter.tags="@LoginValidCredentials or @DashboardTabCountOfQuickLaunhElements or @DirectoryTabNavigationFromDashboardTab or @DirectoryTabIsSearchButtonDisplayed"
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
This command runs only one particular scenario
mvn test -Dcucumber.filter.tags="@LoginValidCredentials"
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
This command runs two scenarios
mvn test -Dcucumber.filter.tags="@LoginValidCredentials or @DashboardTabCountOfQuickLaunhElements"
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
If we use and between two scenarios, none of the scenarios will be executed.
mvn test -Dcucumber.filter.tags="@LoginValidCredentials and @DashboardTabCountOfQuickLaunhElements"
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
To negate a command i.e., to not run a particular scenario use and not
For instance, to run a scenario and to not a run scenario use below format.
mvn test -Dcucumber.filter.tags="@LoginValidCredentials and not @DashboardTabCountOfQuickLaunhElements"
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
1. What is Maven?
Answer: Maven is a build and project management tool used for managing the build lifecycle of a software project. It provides a way to structure a project, manage dependencies, build and test the project, and manage its documentation.
2. Explain the directory structure of a Maven project.
A typical Maven project has the following directory structure:
project-root
├── src
│ ├── main
│ │ ├── java
│ │ ├── resources
│ │ └── webapp
│ └── test
│ ├── java
│ └── resources
├── target
├── pom.xml
└── ...
3. What is a POM in Maven?
POM stands for Project Object Model. It is an XML file that contains information about the project and configuration details for Maven to build the project. It includes details such as project dependencies, plugins, goals, and the build order.
4. What is the purpose of the settings.xml file in Maven?
The settings.xml file is Maven's configuration file. It contains settings that affect the behavior of all Maven builds on a machine, such as the local repository location, mirrors, and authentication details for accessing remote repositories.
5. Explain the Maven build lifecycle.
The Maven build lifecycle consists of three main phases:
Clean: Deletes the target directory to clean up artifacts from previous builds.
Default (or Build): Compiles the source code, runs tests, and creates artifacts.
Site: Generates project documentation and reports.
6. What is a Maven artifact?
In Maven, an artifact is a file, usually a JAR, that gets deployed to a Maven repository.
Artifacts can include compiled code, source code, and project metadata.
Artifacts can include compiled code, source code, and project metadata.
7. Explain the difference between compile, test, and runtime scopes in Maven.
compile: Dependencies needed for compilation and execution.
test: Dependencies used only for testing.
runtime: Dependencies needed for execution but not for compilation.
8. What is the purpose of the dependencyManagement section in a Maven POM?
The dependencyManagement section in a POM is used to define a centralized place to manage dependencies and their versions. It allows you to specify versions in one place and have all projects inherit those versions without explicitly specifying them in each project's POM.
9. What is the purpose of the mvn clean install command?
The mvn clean install command cleans the project, compiles the source code, runs tests, packages the project into a JAR (or another packaging type), and installs it in the local Maven repository. This makes the artifact available for other projects to use.
10. Explain the role of profiles in Maven.
Profiles in Maven allow you to customize the build process based on different environments or conditions. Profiles are defined in the POM and can be activated by various conditions, such as the presence of a system property, an environment variable, or a specific Maven property.
No comments:
Post a Comment