<?xml version="1.0" encoding="UTF-8"?>

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements. See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License. You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<document>

    <properties>
        <title>Testing Conventions in the Apache Harmony Classlib</title>
        <author email="dev@harmony.apache.org">Harmony Documentation Team</author>
    </properties>
    <body>
        <section name="Testing Conventions Used in the Apache Harmony Class Library">
            <p>
                <big><i>This document describes PROPOSED placement and package naming conventions for
                different types of Harmony class library tests.</i></big>
            </p>
            <p>
                The Harmony class library code is organized into modules that might have their own
                specifics. This document provides general guidlines and recomendations that might be
                adapted/modified to reflect module specifics.
            </p>
            <p>
                See also: <a href="ser_testing.html">Framework for Testing Serialization</a>
            </p>

            <subsection name="Location of the Tests in the Directory Tree">
                <p>
                    Each Java class belongs to a specific module of the Harmony class library. Tests against
                    classes belonging to a module belong to the same module. Tests, their resources, and support
                    classes are located under:
                </p>
                <pre>&lt;modulename&gt;/src/test</pre>
                <p>
                    Tests that are specific for Harmony, testing Harmony implementation details, and may fail
                    on RI or other compliant implementations are separated from the implementation-independent
                    tests that must pass on RI and all conformant implementations.
                </p>
<pre>&lt;modulename&gt;/src/test/<b>impl</b> - Harmony specific tests
&lt;modulename&gt;/src/test/<b>api</b> - Implementation-independent tests</pre>
                <p>
                    Special-purpose tests like stress tests or tests that require special configuration are
                    separated from general-purpose tests.
                </p>
<pre>&lt;modulename&gt;/src/test/<b>stress</b></pre>
       <p>
                    Tests are not separated by functionality under test, for example, tests against <code>clone()</code>
                    methods are NOT separated from tests against <code>equals()</code> methods.
                    Find more details <a href="#Package and Class Names for Different Types of the Tests"> below</a>.
                </p>
                <p>
                    The test code is placed in directories as suggested by <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">Apache Maven</a> project conventions:
                </p>
<pre>&lt;modulename&gt;/src/test/api/<b>java</b> - Java code
&lt;modulename&gt;/src/test/api/<b>resources</b> - Test resources</pre>
                <p>
                    Some modules might have implementation specific tests that are in this case separated on a directory level:
                </p>
<pre>&lt;modulename&gt;/src/test/impl/<b>boot</b> - Package private tests
&lt;modulename&gt;/src/test/impl/<b>linux</b> - Linux specific tests
&lt;modulename&gt;/src/test/impl/<b>windows</b> - Windows specific tests</pre>
                 <p>
                    If one pretends to test implementation independent platform-specific functionality, the test should be placed at <code>&lt;modulename&gt;/src/test/api</code> directory and check platforms from test internals.
                 </p>
            </subsection>
            <subsection name="Package and Class Names for Different Types of the Tests">
                <p>
                    If the test is designed to be run from bootclasspath, then its package is the same
                    as the package of the class under the test.
                </p>
                <p>
                    If the test is designed to be run from classpath then:
                </p>
                <ol>
                    <li>
                        If the package under test belongs to a public package, for example, it
                        is a part of the API specification, then the test's package is:
<pre>org.apache.harmony.&lt;modulename&gt;.tests.<b>&lt;package under test&gt;</b></pre>
                        <p class="example">Example</p>
<pre>org.apache.harmony.luni.tests.<b>java.lang</b>
org.apache.harmony.crypto.tests.<b>javax.crypto</b>
org.apache.harmony.auth.tests.<b>org.ietf.jgss</b></pre>
                    </li>
                    <li>
                        If the package under test belongs to <code>org.apache.harmony</code>
                        namespace so that class's package is:
<pre>org.apache.harmony.&lt;modulename&gt;.<b>&lt;rest of the package name&gt;</b></pre>
                        then the test's package is:
<pre>org.apache.harmony.&lt;modulename&gt;.tests.<b>&lt;rest of the package name&gt;</b></pre>
                        <p class="example">Example</p>
                        <p class="exampletext">
                            <code>org.apache.harmony.luni.internal.net.www.protocol</code> - package under test<br/>
                            <code>org.apache.harmony.luni.tests.internal.net.www.protocol</code> - package for the test
                        </p>
                    </li>
                </ol>
                <p>
                    To avoid collision of test results for various type of tests, reflect a test type in a test name.
                </p>
                <p class="example">Example</p>
                <p class="exampletext">
                    To separate the <code>impl</code> test results from
                    the <code>api</code> ones, the <code>impl</code> test names end with
                    <code>_ImplTest</code>:
                </p>
<pre>org.apache.harmony.javax.crypto.tests.javax.crypto.<b>CipherTest</b> - Implementation independent test for <code>javax.crypto.Cipher</code>
org.apache.harmony.javax.crypto.tests.javax.crypto.<b>Cipher_ImplTest</b> - Implementation specific test for <code>javax.crypto.Cipher</code></pre>
            </subsection>
        </section>
    </body>
</document>
