blob: 8494be41f622c2ee5e701ef511decc2a7eda2bbf [file] [log] [blame]
Robert Ly35f2fda2013-01-29 16:27:05 -08001page.title=CTS Development
2@jd:body
3
4<!--
Clay Murphy468ba572015-04-13 18:25:11 -07005 Copyright 2015 The Android Open Source Project
Robert Ly35f2fda2013-01-29 16:27:05 -08006
Clay Murphy468ba572015-04-13 18:25:11 -07007 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 Ly35f2fda2013-01-29 16:27:05 -080010
11 http://www.apache.org/licenses/LICENSE-2.0
12
Clay Murphy468ba572015-04-13 18:25:11 -070013 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 Ly35f2fda2013-01-29 16:27:05 -080017 limitations under the License.
18-->
Clay Murphy468ba572015-04-13 18:25:11 -070019<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 Ly35f2fda2013-01-29 16:27:05 -080026
Clay Murphy468ba572015-04-13 18:25:11 -070027<h2 id="initializing-your-repo-client">Initializing your Repo client</h2>
Clay Murphya69844e2013-05-30 17:56:38 -070028<p>Follow the <a href="{@docRoot}source/downloading.html">instructions</a>
Clay Murphy468ba572015-04-13 18:25:11 -070029to get and build the Android source code but specify a particular CTS branch
30name, for example<code>-b android-5.0_r2</code>, when issuing the <code>repo
31init</code> command. This assures your CTS changes will be included in the
32next CTS release and beyond.</p>
33
34<h2 id="setting-up-eclipse">Setting up Eclipse</h2>
35
Clay Murphya69844e2013-05-30 17:56:38 -070036<p>Follow the <a href="{@docRoot}source/using-eclipse.html">instructions</a>
Robert Ly35f2fda2013-01-29 16:27:05 -080037to setup Eclipse but execute the following command to generate the
38<code>.classpath</code> file rather than copying the one from the development
39project:</p>
40<pre><code>cd /path/to/android/root
41./cts/development/ide/eclipse/genclasspath.sh &gt; .classpath
42chmod u+w .classpath
43</code></pre>
Clay Murphy468ba572015-04-13 18:25:11 -070044
Robert Ly35f2fda2013-01-29 16:27:05 -080045<p>This <code>.classpath</code> file will contain both the Android framework
46packages and the CTS packages.</p>
Clay Murphy468ba572015-04-13 18:25:11 -070047
48<h2 id="building-and-running-cts">Building and running CTS</h2>
49
Robert Ly35f2fda2013-01-29 16:27:05 -080050<p>Execute the following commands to build CTS and start the interactive
51CTS console:</p>
Clay Murphy468ba572015-04-13 18:25:11 -070052<p class="note"><strong>Note:</strong> You may supply one of these other values
53for <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>
56make cts -j32 TARGET_PRODUCT=aosp_arm64
Robert Ly35f2fda2013-01-29 16:27:05 -080057cts-tradefed
58</code></pre>
Clay Murphy468ba572015-04-13 18:25:11 -070059
Robert Ly35f2fda2013-01-29 16:27:05 -080060<p>At the cts-tf console, enter e.g.:</p>
61<pre><code>run cts --plan CTS
62</code></pre>
Clay Murphy468ba572015-04-13 18:25:11 -070063
64<h2 id="writing-cts-tests">Writing CTS tests</h2>
65
Robert Ly35f2fda2013-01-29 16:27:05 -080066<p>CTS tests use JUnit and the Android testing APIs. Review the
Clay Murphy468ba572015-04-13 18:25:11 -070067<a href="https://developer.android.com/tools/testing/testing_android.html">Testing and Instrumentation</a>
Robert Ly35f2fda2013-01-29 16:27:05 -080068tutorial while perusing the existing tests under the
Clay Murphy468ba572015-04-13 18:25:11 -070069<code>cts/tests</code> directory. You will see that CTS tests mostly follow the same
Robert Ly35f2fda2013-01-29 16:27:05 -080070conventions used in other Android tests.</p>
71<p>Since CTS runs across many production devices, the tests must follow
72these 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 Murphy468ba572015-04-13 18:25:11 -070079
80<h3 id="test-naming-and-location">Test naming and location</h3>
81
Robert Ly35f2fda2013-01-29 16:27:05 -080082<p>Most CTS test cases target a specific class in the Android API. These tests
83have Java package names with a <code>cts</code> suffix and class
84names with the <code>Test</code> suffix. Each test case consists of
85multiple tests, where each test usually exercises a particular API method of
86the API class being tested. These tests are arranged in a directory structure
87where tests are grouped into different categories like "widgets" and "views."</p>
Clay Murphy468ba572015-04-13 18:25:11 -070088
Robert Ly35f2fda2013-01-29 16:27:05 -080089<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
92Java 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>
94that exercises the "setText" method and a test named "testSetSingleLine" that
95calls the <code>setSingleLine</code> method. Each of those tests have <code>@TestTargetNew</code>
96annotations indicating what they cover.</p>
Clay Murphy468ba572015-04-13 18:25:11 -070097
Robert Ly35f2fda2013-01-29 16:27:05 -080098<p>Some CTS tests do not directly correspond to an API class but are placed in
99the 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
101is network related even though there is no <code>android.net.ListeningPorts</code> class.
102You 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
104best judgement when adding new tests and refer to other tests as examples.</p>
Clay Murphy468ba572015-04-13 18:25:11 -0700105
Robert Ly35f2fda2013-01-29 16:27:05 -0800106<p>Finally, a lot of tests are annotated with @TestTargets and @TestTargetNew.
107These are no longer necessary so do not annotate new tests with these.</p>
Clay Murphy468ba572015-04-13 18:25:11 -0700108<h3 id="new-test-packages">New sample packages</h3>
Robert Ly35f2fda2013-01-29 16:27:05 -0800109<p>When adding new tests, there may not be an existing directory to place your
110test. In that case, refer to the example under <code>cts/tests/tests/example</code> and
111create a new directory. Furthermore, make sure to add your new package's
112module 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>
114to glue all the tests together to create the final CTS package.</p>
Clay Murphy468ba572015-04-13 18:25:11 -0700115
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
118remove 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 Ly35f2fda2013-01-29 16:27:05 -0800121to contribute changes to CTS. A reviewer
122will be assigned to your change, and your change should be reviewed shortly!</p>