Maven interview questions
Updated 2026-11-13 · 8 min read
Thirty questions with practical answers, common mistakes and scenarios for testers preparing for interviews.
Build fundamentals
1. Why do testers use Maven?
Maven describes how a Java project obtains dependencies and runs build tasks consistently. A tester can use the same checked-in project definition locally and in CI. Maven does not write assertions or replace the test framework.
2. What is pom.xml?
The Project Object Model describes project coordinates, dependencies, build plugins and other configuration. It can inherit configuration from a parent. When a test behaves differently in CI, inspect the effective configuration rather than only the nearest POM.
3. What are groupId, artifactId and version?
Together they identify a project artifact, such as a team’s reusable test helper. A versioned artifact lets consumers request a particular published build. A Java package name and Maven group ID may look similar but are not the same mechanism.
4. What is Maven’s conventional test layout?
Java test sources normally go in src/test/java, while test resources go in src/test/resources. Application sources belong in src/main/java. A test hidden in a nonstandard folder will not be discovered unless the build explicitly configures that folder.
5. What is a lifecycle?
A lifecycle is an ordered sequence of phases. Maven has default, clean and site lifecycles. Requesting a phase executes the earlier phases in that lifecycle; requesting a default-lifecycle phase does not automatically run the separate clean lifecycle.
6. What is a phase versus a plugin goal?
A phase is a point in a lifecycle, such as test or package. A plugin goal is executable work that can be bound to a phase or invoked directly. “Surefire runs tests” names plugin behavior; “test” also names the lifecycle phase that normally invokes it.
7. How do test, package, verify, install and deploy differ?
Test runs the bound test work; package creates the configured artifact; verify performs later verification work. Install places the artifact in the local repository and deploy publishes it to a configured remote repository. Maven deploy does not mean deploying the tested web application.
8. Why might you run clean before verify?
Clean removes prior build output, helping rule out stale compiled classes and old reports. It also removes reusable output, so do not treat it as free. Use a clean build when reproducing a suspicious local-versus-CI difference.
Dependencies and plugins
9. What does dependency scope control?
Scope controls which classpaths receive a dependency and affects transitive propagation. A test-only assertion library usually uses test scope. Adding every dependency with compile scope can accidentally make test utilities part of a production consumer’s dependency graph.
10. What is compile scope?
It is the default scope when none is specified and makes a dependency available broadly to the project’s compilation and runtime paths. It is appropriate for code required by application sources. A repository containing only test tooling still needs to choose scopes according to where its source files live.
11. What is test scope?
It makes a dependency available for test compilation and test execution, rather than normal application compilation. For example, test sources can use an assertion library without main sources depending on it. Such dependencies are not transitively supplied to downstream projects.
12. How do provided and runtime differ?
Provided indicates an API needed for compilation whose implementation is expected from the runtime environment. Runtime makes a dependency available at runtime without the normal main compile classpath. A JDBC driver may be runtime while a container API may be provided; choose based on the actual deployment.
13. What is a transitive dependency?
A direct dependency can bring dependencies of its own. This saves manual declarations but can introduce conflicting library versions. A browser test failing during startup may have a classpath conflict before it ever contacts the browser.
14. How does Maven resolve conflicting dependency versions?
The usual mediation rule chooses the nearest declaration in the dependency graph; at the same depth, declaration order matters. Dependency management can control selected versions. It does not simply choose whichever version number is highest.
15. What is dependencyManagement?
It centralizes dependency version and related defaults for declarations that use them. It does not by itself add every listed library to the project. This is useful when several test modules must use a consistent HTTP client version.
16. How do plugins differ from dependencies?
Dependencies are libraries consumed by project code; plugins execute build tasks. Adding a runner library does not configure every aspect of the plugin that launches tests. Similarly, pluginManagement provides defaults but does not necessarily activate arbitrary plugin executions.
Running and diagnosing tests
17. What is Surefire used for?
Surefire launches tests during the test phase in the usual Java build setup and writes reports under target/surefire-reports. Provider support depends on the configured plugin and test framework. Pin compatible versions rather than relying on whatever an old parent happened to choose.
18. How do you run one test class?
Surefire documents the test property for selecting a class. This command is documentation-checked but was not run here because a usable JDK and Maven were unavailable. It requires a real project containing LoginTest.
mvn -Dtest=LoginTest test
19. Why might a test class not run?
Check source location, compiled output, naming includes and excludes, selected provider and framework annotations. A class name outside the configured discovery patterns can be missed even when it compiles. Inspect the report and discovered test count rather than accepting BUILD SUCCESS alone.
20. How do you inspect dependency conflicts?
A dependency tree reveals paths introducing competing libraries. Check the selected version and omitted alternatives before changing exclusions. This documentation-checked command was not executed here.
mvn dependency:tree
21. How do you inspect inherited build configuration?
The effective POM includes inherited and active-profile configuration. It can expose a test skip setting hidden in a parent. This documentation-checked command was not executed here.
mvn help:effective-pom
22. What is Failsafe used for?
Failsafe supports integration-test and verify work so cleanup can occur before failures are finally evaluated. Configure its executions deliberately; merely naming a class with an integration-test pattern is not enough to bind the plugin. Invoke verify rather than stopping at integration-test when using that lifecycle arrangement.
23. How do skipTests and maven.test.skip differ?
Surefire’s skipTests skips test execution while test compilation normally still occurs. The maven.test.skip property is also honored by the compiler and can skip test compilation. Confirm the plugins in your build before using either, and never present a skipped suite as a passing suite.
24. Where should test failures be published in CI?
Retain XML reports and useful sanitized logs even when the test command fails. Check whether the pipeline correctly preserves the command’s nonzero exit status. A report upload step must not turn a genuine test failure into a green quality gate.
Configuration and scenarios
25. What is a Maven profile?
A profile supplies conditional build configuration. It can support a documented variation such as a smoke-suite selection, but excessive profiles make the effective build difficult to understand. Keep environment credentials outside committed profile values.
26. How can a profile define a non-secret environment name?
This complete illustrative POM defines a property and a profile override; it does not add a test framework or automatically pass the property into tests. XML syntax was parsed, but Maven execution was not verified here. The chosen project version belongs to this fake example.
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example.qa</groupId>
<artifactId>test-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<test.environment>local</test.environment>
</properties>
<profiles>
<profile>
<id>staging</id>
<properties>
<test.environment>staging</test.environment>
</properties>
</profile>
</profiles>
</project>
27. What is the local repository?
It caches downloaded artifacts and holds locally installed artifacts, commonly under the user’s .m2/repository. It is different from the project’s target directory. A missing or corrupted cached artifact calls for targeted diagnosis rather than deleting every cached library first.
28. How do release and SNAPSHOT dependencies differ?
A snapshot represents work in progress and can resolve to changing timestamped builds. A release dependency expresses a stable version expectation, subject to repository policy. Prefer controlled dependencies when reproducing a historic test run; a changing snapshot can make the same source commit behave differently.
29. Why might Maven work locally but fail in CI?
Compare JDK, Maven, active profiles, repository access, settings and cached artifacts. A locally installed unpublished helper can hide a missing dependency publication step. Check a clean environment rather than copying the developer’s entire local repository into CI.
30. What would you explain about a Maven-based framework in an interview?
Trace one command from dependency resolution through test discovery to reports and the pipeline gate. Name which behavior comes from Maven, the runner and the browser library. Be explicit about configuration you inspected versus builds you actually executed.
Likely follow-up: What if BUILD SUCCESS reports no tests? Inspect discovery and enforce an expected test count or appropriate fail-on-no-tests policy.
Practise it
For your own Java test project, explain its dependency tree and report location. Use ShopLite as a local target once you have configured a suitable runner and browser or HTTP library.
Quick answers
Does Maven replace TestNG or JUnit?
No. Maven runs build tasks; test frameworks define and execute tests through the configured provider.
Does deploy release the application to a server?
Maven deploy publishes artifacts to a configured repository. Application deployment is a separate concern.
Sources
- Standard directory layout (official documentation, accessed 2026-11-13)
- Maven lifecycle (official documentation, accessed 2026-11-13)
- Dependency mechanism (official documentation, accessed 2026-11-13)
- Surefire single tests (official documentation, accessed 2026-11-13)
- Skipping tests (official documentation, accessed 2026-11-13)
- Build profiles (official documentation, accessed 2026-11-13)
- Failsafe (official documentation, accessed 2026-11-13)
- Dependency tree (official documentation, accessed 2026-11-13)
- Effective POM (official documentation, accessed 2026-11-13)
Want a project you can show in interviews?
The portfolio project kit walks you through testing a deliberately buggy app with Selenium or Playwright and API tests, then explaining it. The app itself is free.
