Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 1 | page.title=CTS Development |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 5 | Copyright 2015 The Android Open Source Project |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 6 | |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 17 | limitations under the License. |
| 18 | --> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 19 | <div id="qv-wrapper"> |
| 20 | <div id="qv"> |
| 21 | <h2>In this document</h2> |
| 22 | <ol id="auto-toc"> |
| 23 | </ol> |
| 24 | </div> |
| 25 | </div> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 26 | |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 27 | <h2 id="initializing-your-repo-client">Initializing your Repo client</h2> |
Clay Murphy | a69844e | 2013-05-30 17:56:38 -0700 | [diff] [blame] | 28 | <p>Follow the <a href="{@docRoot}source/downloading.html">instructions</a> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 29 | to get and build the Android source code but specify a particular CTS branch |
| 30 | name, for example<code>-b android-5.0_r2</code>, when issuing the <code>repo |
| 31 | init</code> command. This assures your CTS changes will be included in the |
| 32 | next CTS release and beyond.</p> |
| 33 | |
| 34 | <h2 id="setting-up-eclipse">Setting up Eclipse</h2> |
| 35 | |
Clay Murphy | a69844e | 2013-05-30 17:56:38 -0700 | [diff] [blame] | 36 | <p>Follow the <a href="{@docRoot}source/using-eclipse.html">instructions</a> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 37 | to setup Eclipse but execute the following command to generate the |
| 38 | <code>.classpath</code> file rather than copying the one from the development |
| 39 | project:</p> |
| 40 | <pre><code>cd /path/to/android/root |
| 41 | ./cts/development/ide/eclipse/genclasspath.sh > .classpath |
| 42 | chmod u+w .classpath |
| 43 | </code></pre> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 44 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 45 | <p>This <code>.classpath</code> file will contain both the Android framework |
| 46 | packages and the CTS packages.</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 47 | |
| 48 | <h2 id="building-and-running-cts">Building and running CTS</h2> |
| 49 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 50 | <p>Execute the following commands to build CTS and start the interactive |
| 51 | CTS console:</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 52 | <p class="note"><strong>Note:</strong> You may supply one of these other values |
| 53 | for <code>TARGET_PRODUCT</code> to build for different architectures: |
| 54 | <code>aosp_x86_64</code> or <code>aosp_mips</code></p> |
| 55 | <pre><code>cd <em>/path/to/android/root</em> |
| 56 | make cts -j32 TARGET_PRODUCT=aosp_arm64 |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 57 | cts-tradefed |
| 58 | </code></pre> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 59 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 60 | <p>At the cts-tf console, enter e.g.:</p> |
| 61 | <pre><code>run cts --plan CTS |
| 62 | </code></pre> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 63 | |
| 64 | <h2 id="writing-cts-tests">Writing CTS tests</h2> |
| 65 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 66 | <p>CTS tests use JUnit and the Android testing APIs. Review the |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 67 | <a href="https://developer.android.com/tools/testing/testing_android.html">Testing and Instrumentation</a> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 68 | tutorial while perusing the existing tests under the |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 69 | <code>cts/tests</code> directory. You will see that CTS tests mostly follow the same |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 70 | conventions used in other Android tests.</p> |
| 71 | <p>Since CTS runs across many production devices, the tests must follow |
| 72 | these rules:</p> |
| 73 | <ul> |
| 74 | <li>Must take into account varying screen sizes, orientations, and keyboard layouts.</li> |
| 75 | <li>Only use public API methods. In other words, avoid all classes, methods, and fields that are annotated with the "hide" annotation.</li> |
| 76 | <li>Avoid relying upon particular view layouts or depend on the dimensions of assets that may not be on some device.</li> |
| 77 | <li>Don't rely upon root privileges.</li> |
| 78 | </ul> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 79 | |
| 80 | <h3 id="test-naming-and-location">Test naming and location</h3> |
| 81 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 82 | <p>Most CTS test cases target a specific class in the Android API. These tests |
| 83 | have Java package names with a <code>cts</code> suffix and class |
| 84 | names with the <code>Test</code> suffix. Each test case consists of |
| 85 | multiple tests, where each test usually exercises a particular API method of |
| 86 | the API class being tested. These tests are arranged in a directory structure |
| 87 | where tests are grouped into different categories like "widgets" and "views."</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 88 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 89 | <p>For example, the CTS test for <code>android.widget.TextView</code> is |
| 90 | <code>android.widget.cts.TextViewTest</code> found under the |
| 91 | <code>cts/tests/tests/widget/src/android/widget/cts</code> directory with its |
| 92 | Java package name as <code>android.widget.cts</code> and its class name as |
| 93 | <code>TextViewTest</code>. The <code>TextViewTest</code> class has a test called <code>testSetText</code> |
| 94 | that exercises the "setText" method and a test named "testSetSingleLine" that |
| 95 | calls the <code>setSingleLine</code> method. Each of those tests have <code>@TestTargetNew</code> |
| 96 | annotations indicating what they cover.</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 97 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 98 | <p>Some CTS tests do not directly correspond to an API class but are placed in |
| 99 | the most related package possible. For instance, the CTS test, |
| 100 | <code>android.net.cts.ListeningPortsTest</code>, is in the <code>android.net.cts</code>, because it |
| 101 | is network related even though there is no <code>android.net.ListeningPorts</code> class. |
| 102 | You can also create a new test package if necessary. For example, there is an |
| 103 | "android.security" test package for tests related to security. Thus, use your |
| 104 | best judgement when adding new tests and refer to other tests as examples.</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 105 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 106 | <p>Finally, a lot of tests are annotated with @TestTargets and @TestTargetNew. |
| 107 | These are no longer necessary so do not annotate new tests with these.</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 108 | <h3 id="new-test-packages">New sample packages</h3> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 109 | <p>When adding new tests, there may not be an existing directory to place your |
| 110 | test. In that case, refer to the example under <code>cts/tests/tests/example</code> and |
| 111 | create a new directory. Furthermore, make sure to add your new package's |
| 112 | module name from its <code>Android.mk</code> to <code>CTS_COVERAGE_TEST_CASE_LIST</code> in |
| 113 | <code>cts/CtsTestCaseList.mk</code>. This Makefile is used by <code>build/core/tasks/cts.mk</code> |
| 114 | to glue all the tests together to create the final CTS package.</p> |
Clay Murphy | 468ba57 | 2015-04-13 18:25:11 -0700 | [diff] [blame^] | 115 | |
| 116 | <h2 id="Fix-remove-tests">Fix or remove tests</h2> |
| 117 | <p>Besides adding new tests there are other ways to contribute to CTS: Fix or |
| 118 | remove tests annotated with "BrokenTest" or "KnownFailure."</p> |
| 119 | <h2 id="submitting-your-changes">Submitting your changes</h2> |
| 120 | <p>Follow the <a href="{@docRoot}source/submit-patches.html">Submitting Patches workflow</a> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 121 | to contribute changes to CTS. A reviewer |
| 122 | will be assigned to your change, and your change should be reviewed shortly!</p> |