Here are multiple-choice questions (MCQs) covering creating and running Maven tests, various Maven commands, running single or multiple Maven tests from the command line, building Maven projects, and using the Maven Surefire plugin with TestNG.
1. Which command is used to create a new Maven test class in a Maven project?
A) mvn new test
B) mvn create:test
C) Manually create the test class in src/test/java
D) mvn add test
Answer: C) Manually create the test class in src/test/java
2. How do you run all tests in a Maven project from the command line?
A) mvn compile
B) mvn test
C) mvn install
D) mvn run-tests
Answer: B) mvn test
3. What does the Maven command mvn clean do?
A) Cleans up the src folder
B) Deletes the target directory and its contents
C) Deletes the pom.xml file
D) Compiles the project
Answer: B) Deletes the target directory and its contents
4. Which Maven command compiles the source code of the project?
A) mvn compile
B) mvn clean
C) mvn test
D) mvn package
Answer: A) mvn compile
5. How can you run a single test method in Maven from the command line?
A) mvn test -Dtest=ClassName#methodName
B) mvn run -Dtest=ClassName.methodName
C) mvn single-test -Dtest=ClassName.methodName
D) mvn test -single=ClassName#methodName
Answer: A) mvn test -Dtest=ClassName#methodName
6. How do you run multiple specific tests using Maven from the command line?
A) mvn test -Dtest=TestClass1,TestClass2
B) mvn test -Dtests=TestClass1,TestClass2
C) mvn run -Dtest=TestClass1,TestClass2
D) mvn test -Dtest=TestClass1+TestClass2
Answer: A) mvn test -Dtest=TestClass1,TestClass2
7. Which command is used to build a Maven project and package the compiled code into a distributable format?
A) mvn compile
B) mvn clean
C) mvn build
D) mvn package
Answer: D) mvn package
8. What is the role of the Maven Surefire plugin when working with TestNG?
A) It is used to compile Java code
B) It is used to run unit tests and generate reports
C) It is used to manage project dependencies
D) It is used to package the project
Answer: B) It is used to run unit tests and generate reports
9. How do you specify a TestNG XML file to run using Maven and the Surefire plugin?
A) Add the XML file in the src/test/resources directory
B) Configure the <suiteXmlFiles> tag in the pom.xml under the Surefire plugin configuration
C) Specify the XML file in the command line with mvn test -Dtestng.xml
D) Mention the XML file in settings.xml
Answer: B) Configure the <suiteXmlFiles> tag in the pom.xml under the Surefire plugin configuration
10. Which of the following is the correct Maven command to run a testng.xml file from the command line?
A) mvn test -DxmlFile=testng.xml
B) mvn test -Dsurefire.suiteXmlFiles=testng.xml
C) mvn surefire:test -Dtestng.xml
D) mvn test -Dtest=testng.xml
Answer: B) mvn test -Dsurefire.suiteXmlFiles=testng.xml
11. What does the mvn clean install command do in a Maven project?
A) Cleans the project and packages the compiled code
B) Cleans the project and compiles the code
C) Cleans the project, compiles the code, runs the tests, and installs the package into the local repository
D) Only cleans the project
Answer: C) Cleans the project, compiles the code, runs the tests, and installs the package into the local repository
12. Which Maven phase runs after the test phase if all tests pass successfully?
A) compile
B) verify
C) package
D) clean
Answer: B) verify
14. What is the purpose of the mvn install command?
A) To install Maven on the system
B) To compile and test the project
C) To compile, test, and install the built package to the local repository
D) To run integration tests
Answer: C) To compile, test, and install the built package to the local repository
15. How do you exclude a specific test from being run by Maven?
A) By configuring the <exclude> tag in pom.xml under Surefire plugin
B) By using the -Dexcludes option on the command line
C) By commenting out the test method
D) By removing the test class from the src/test/java directory
Answer: A) By configuring the <exclude> tag in pom.xml under Surefire plugin
18. Which command would you use to clean and compile a Maven project?
A) mvn clean compile
B) mvn compile clean
C) mvn clean build
D) mvn clean
Answer: A) mvn clean compile
19. What is the correct Maven command to run a single test class using the Surefire plugin?
A) mvn surefire:test -Dtest=TestClass
B) mvn test -Dtest=TestClass
C) mvn run -Dtest=TestClass
D) mvn surefire:run -Dtest=TestClass
Answer: B) mvn test -Dtest=TestClass
20. Which Maven phase comes before the install phase in the default Maven lifecycle?
A) verify
B) clean
C) package
D) deploy
Answer: C) package
These MCQs cover the essentials of using Maven for running tests, executing commands, managing the build lifecycle, and integrating with TestNG using the Maven Surefire plugin.
No comments:
Post a Comment