This guide explains how to run different types of tests in Apache Ambari. For the official test configuration, you can refer to the Ambari Jenkinsfile.
To run all Java tests for the Ambari Server:
mvn -am test -pl ambari-server \ -DskipPythonTests \ -Dmaven.test.failure.ignore \ -Dmaven.artifact.threads=10 \ -Drat.skip \ -DskipAdminWebTests=true
To run a specific Java test class:
mvn -am test -pl ambari-server \ -DskipPythonTests \ -Dmaven.test.failure.ignore \ -Dmaven.artifact.threads=10 \ -Drat.skip \ -DskipAdminWebTests=true \ -Dtest=AmbariServerTest
To run a specific test method within a test class:
mvn -am test -pl ambari-server \ -DskipPythonTests \ -Dmaven.test.failure.ignore \ -Dmaven.artifact.threads=10 \ -Drat.skip \ -DskipAdminWebTests=true \ -Dtest=AmbariServerTest#testMethodName
-am: Also build dependencies-pl ambari-server: Only build the ambari-server module-DskipPythonTests: Skip Python tests-Dmaven.test.failure.ignore: Continue the build even if tests fail-Dmaven.artifact.threads=10: Use 10 threads for parallel artifact resolution-Drat.skip: Skip Apache RAT (Release Audit Tool) checks-DskipAdminWebTests: Skip admin web interface tests-Dtest: Specify which test class or method to runTo run all Python tests:
mvn test -pl ambari-server \ -DskipJavaTests \ -Dpython.test.mask="*_test.py" \ -Dpython.test.skip.pattern="agent_perf.py"
To run a specific Python test file:
mvn test -pl ambari-server \ -DskipJavaTests \ -Dpython.test.mask="test_file_name.py"
-DskipJavaTests: Skip Java tests-Dpython.test.mask: Pattern to match test files to run-Dpython.test.skip.pattern: Pattern to match test files to skipTo run integration tests:
mvn verify -pl ambari-server \ -P integration-tests \ -DskipPythonTests \ -DskipJavaTests
-P integration-tests: Activate the integration-tests profile-DskipPythonTests: Skip Python tests-DskipJavaTests: Skip Java testsTest reports can be found in the following locations after test execution:
ambari-server/target/surefire-reports/ambari-server/target/failsafe-reports/ambari-server/target/python-test-results/ambari-server/target/python-coverage/:::tip When debugging test failures, check these report directories for detailed test execution logs and stack traces. :::
Ambari Metrics requires a few more prerequisite for unit testing.
yum install -y krb5-devel pip3 install distro kerberos
To run all Java tests for the Ambari Metrics:
mvn test \ -DskipPythonTests \ -Dmaven.test.failure.ignore \ -Dmaven.artifact.threads=10 \ -Drat.skip
To run all Java tests for the Ambari Metrics:
mvn test \ -Dmaven.test.failure.ignore \ -Dmaven.artifact.threads=10 \ -Drat.skip