1*c2e18aaaSAndroid Build Coastguard Worker# Test Runner Developer Guide 2*c2e18aaaSAndroid Build Coastguard Worker 3*c2e18aaaSAndroid Build Coastguard WorkerLearn about test runners and how to create a new test runner class. 4*c2e18aaaSAndroid Build Coastguard Worker 5*c2e18aaaSAndroid Build Coastguard Worker##### Table of Contents 6*c2e18aaaSAndroid Build Coastguard Worker1. [Test Runner Details](#test-runner-details) 7*c2e18aaaSAndroid Build Coastguard Worker2. [Creating a Test Runner](#creating-a-test-runner) 8*c2e18aaaSAndroid Build Coastguard Worker 9*c2e18aaaSAndroid Build Coastguard Worker## <a name="test-runner-details">Test Runner Details</a> 10*c2e18aaaSAndroid Build Coastguard Worker 11*c2e18aaaSAndroid Build Coastguard WorkerThe test runner class is responsible for test execution. Its primary logic 12*c2e18aaaSAndroid Build Coastguard Workerinvolve construction of the commandline given a ```TestInfo``` and 13*c2e18aaaSAndroid Build Coastguard Worker```extra_args``` passed into the ```run_tests``` method. The extra_args are 14*c2e18aaaSAndroid Build Coastguard Workertop-level args consumed by atest passed onto the test runner. It is up to the 15*c2e18aaaSAndroid Build Coastguard Workertest runner to translate those args into the specific args the test runner 16*c2e18aaaSAndroid Build Coastguard Workeraccepts. In this way, you can think of the test runner as a translator between 17*c2e18aaaSAndroid Build Coastguard Workerthe atest CLI and your test runner's CLI. The reason for this is so that atest 18*c2e18aaaSAndroid Build Coastguard Workercan have a consistent CLI for args instead of requiring the users to remember 19*c2e18aaaSAndroid Build Coastguard Workerthe differing CLIs of various test runners. The test runner should also 20*c2e18aaaSAndroid Build Coastguard Workerdetermine its specific dependencies that need to be built prior to any test 21*c2e18aaaSAndroid Build Coastguard Workerexecution. 22*c2e18aaaSAndroid Build Coastguard Worker 23*c2e18aaaSAndroid Build Coastguard Worker## <a name="creating-a-test-runner">Creating a Test Runner</a> 24*c2e18aaaSAndroid Build Coastguard Worker 25*c2e18aaaSAndroid Build Coastguard WorkerFirst thing to choose is where to put the test runner. This will primarily 26*c2e18aaaSAndroid Build Coastguard Workerdepend on if the test runner will be public or private. If public, 27*c2e18aaaSAndroid Build Coastguard Worker```test_runners/``` is the default location. 28*c2e18aaaSAndroid Build Coastguard Worker 29*c2e18aaaSAndroid Build Coastguard Worker> If it will be private, then you can 30*c2e18aaaSAndroid Build Coastguard Worker> follow the same instructions for ```vendorsetup.sh``` in 31*c2e18aaaSAndroid Build Coastguard Worker> [constants override](atest_structure.md#constants-override) where you will 32*c2e18aaaSAndroid Build Coastguard Worker> add the path of where the test runner lives into ```$PYTHONPATH```. Same 33*c2e18aaaSAndroid Build Coastguard Worker> rules apply, rerun ```build/envsetup.sh``` to update ```$PYTHONPATH```. 34*c2e18aaaSAndroid Build Coastguard Worker 35*c2e18aaaSAndroid Build Coastguard WorkerTo create a new test runner, create a new class that inherits 36*c2e18aaaSAndroid Build Coastguard Worker```TestRunnerBase```. Take a look at ```test_runners/example_test_runner.py``` 37*c2e18aaaSAndroid Build Coastguard Workerto see what a simple test runner will look like. 38*c2e18aaaSAndroid Build Coastguard Worker 39*c2e18aaaSAndroid Build Coastguard Worker**Important Notes** 40*c2e18aaaSAndroid Build Coastguard WorkerYou'll need to override the following parent methods: 41*c2e18aaaSAndroid Build Coastguard Worker* ```host_env_check()```: Check if host environment is properly setup for the 42*c2e18aaaSAndroid Build Coastguard Worker test runner. Raise an expception if not. 43*c2e18aaaSAndroid Build Coastguard Worker* ```get_test_runner_build_reqs()```: Return a set of build targets that need 44*c2e18aaaSAndroid Build Coastguard Worker to be built prior to test execution. 45*c2e18aaaSAndroid Build Coastguard Worker* ```run_tests()```: Execute the test(s). 46*c2e18aaaSAndroid Build Coastguard Worker 47*c2e18aaaSAndroid Build Coastguard WorkerAnd define the following class vars: 48*c2e18aaaSAndroid Build Coastguard Worker* ```NAME```: Unique name of the test runner. 49*c2e18aaaSAndroid Build Coastguard Worker* ```EXECUTABLE```: Test runner command, should be an absolute path if the 50*c2e18aaaSAndroid Build Coastguard Worker command can not be found in ```$PATH```. 51*c2e18aaaSAndroid Build Coastguard Worker 52*c2e18aaaSAndroid Build Coastguard WorkerThere is a parent helper method (```run```) that should be used to execute the 53*c2e18aaaSAndroid Build Coastguard Workeractual test command. 54*c2e18aaaSAndroid Build Coastguard Worker 55*c2e18aaaSAndroid Build Coastguard WorkerOnce the test runner class is created, you'll need to add it in 56*c2e18aaaSAndroid Build Coastguard Worker```test_runner_handler``` so that atest is aware of it. Try-except import the 57*c2e18aaaSAndroid Build Coastguard Workertest runner in ```_get_test_runners``` like how ```ExampleTestRunner``` is. 58*c2e18aaaSAndroid Build Coastguard Worker```python 59*c2e18aaaSAndroid Build Coastguard Workertry: 60*c2e18aaaSAndroid Build Coastguard Worker from test_runners import new_test_runner 61*c2e18aaaSAndroid Build Coastguard Worker test_runners_dict[new_test_runner.NewTestRunner.NAME] = new_test_runner.NewTestRunner 62*c2e18aaaSAndroid Build Coastguard Workerexcept ImportError: 63*c2e18aaaSAndroid Build Coastguard Worker pass 64*c2e18aaaSAndroid Build Coastguard Worker``` 65