0% found this document useful (0 votes)
2 views57 pages

JTREG Tool: Java Testing Guide

JTREG TUTORIAL Java Library

Uploaded by

dmdanilo39
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views57 pages

JTREG Tool: Java Testing Guide

JTREG TUTORIAL Java Library

Uploaded by

dmdanilo39
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JTREG TUTORIAL

March 01, 2013

§ Balchandra Vaidya

1Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13
The following is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into
any contract. It is not a commitment to deliver
any material, code, or functionality, and should
not be relied upon in making purchasing
decisions. The development, release, and timing
of any features or functionality described for
Oracle’s products remains at the sole discretion
of Oracle.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


2
Table of Contents

Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


1. Introduction
§ The primary purpose of jtreg tool is for developing unit tests


It can also be used for writing functional tests.

§ The jtreg tool can be used for developing and running tests for java APIs,
compilers, VM and GUI components.

§ The jtreg tool use JavaTest harness which is a set of tools designed to
execute test programs. [Link]

§ Information about jtreg is available at


[Link]

[Link]

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


5
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


2. Nuts and Bolts (1/4)
§ A test case is a

java program with usual static main method (main test)


an applet (applet test)


a shell script (shell test)

§ A test case should define Pass-Fail criteria.


if the test fails, it should throw an exception.


if it succeeds, it should return normally.


Not recommended to catch general exceptions such as Throwable,
Exception, or Error.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


7
2. Nuts and Bolts (2/4)
§ A test case is distinguished and controlled by tags

@test tag identifies a source file that defines a test. This is a
mandatory tag. This must be the first tag in a comment block

@run tag tells the harness how to perform the test.

@summary tag is used to provide brief description of the test case.

@library tag is used to reference library source files.

@build tag is used to compile dependent classes or libraries before
running the tests

@compile tag is used to compile a class. It is useful for writing
compiler tests
§ More tags and options are available in

doc/jtreg/[Link] in jtreg bundle

jtreg -onlineHelp
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
8
2. Nuts and Bolts(3/4)

§ @run tag is optional for automated tests


This tag can be used to run tests with non-default options.
§ Manual tests use /manual option with @run tag

@run applet/manual

@run main/manual

@run shell/manual
§ Negative test is marked with /fail option


@run main/fail

@compile/fail

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


9
2. Nuts and Bolts (4/4)

§ Applet test requires an HTML file which should contain an applet tag with
any necessary parameters.


Extension should be .html

§ Shell tests should



have extension .sh


use Bourne shell syntax

§ Test fails if tests take longer than 120 seconds


It can be controlled by /timeout option e.g. @run main/timeout=100

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


10
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


3. Test Execution
General Options JDK Options
-gui -vmoptions
-ignore -ea
-reportDir -client
....... .......

jtreg -concurrency:auto -server -testjdk:${TESTJDK}


-othervm -automatic -verbose:summary ./examples

Test Mode Test Selection Verbose Tests


-agentvm -automatic -summary -directory
-samevm -manual -pass -Testcase
-othervm -exclude -fail
....... .......

§ Online help: jtreg -onlineHelp

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


12
3. Test Execution (1/4)

§ Verbose options

amount of output written to the console while running tests.

-verbose:summary, -verbose:fail,error, ..
§ Test selection options

-a | -automatic can be used to run automatic tests

-m | -manual can be used to run manual tests

-k:<keywordExpr> can be used to run only tests with <keywordExpr>
which is a simple boolean expression containing keywords

-bug:<bugid> can be used to run only tests with <bugid>

All tests run by default

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


13
[Link] Execution (2/4)

§ Test Mode

-othervm : Run every test in its own JVM; maximum isolation between
tests; maximum overhead

-samevm : Run each test in the same JVM as the JavaTest harness;
minimum overhead; minimum isolation between tests; one bad test can
cause problems for all subsequent tests

-agentvm : Run tests using a pool of reusable JVMs; reuse vm if it can
be reset to a clean state after a test; cannot be enforced in a test

Test mode can also be specified in a test source file e.g. @run
main/agentvm, @run main/othervm/timeout=300
§ Tests can be run concurrently using -conc:N | -concurrency:N option

This option can not be used with -samevm option

Not suitable for GUI tests e.g. a test require mouse interaction
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
14
[Link] Execution (3/4)

§ JDK options

-vmoption can be used to pass all applicable JVM options

Most common JVM options, e.g. -server, -d64, -client etc. are
supported directly
§ Test JDK

-testjdk can be used to pass JDK version for testing

JDK version used for running 'jtreg' harness is tested by default
§ Excluding testcases

[Link] can contain known failing tests.

-exclude:[Link] excludes tests present in the files from
executing.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


15
3. Test Execution (4/4)
§ Test log is written to a text file with .jtr extension.

Contains the command used to execute tests

Contains diagnostic message included in exception

Contains output of [Link] and [Link]
§ Report and log files are written to JTreport and JTwork directory, by default

JTwork directory contains .jtr files and .class files.

JTreport directory contains html summary report and [Link]

-r and -w options can be used to specify non-default work and report
directory
§ -xml option can be used to produce test log files in xml format

Log files with .[Link] extension are found in JTwork directory

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


16
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


4. An Example (1/5)

/* @test Indicates source is a test


@summary Example1 - a simple testcase
@run main Example1
*/
import [Link].*;
import [Link].*;

public class Example1 {


public static void main(String[] args) throws Exception {
JLayer l = new JLayer();
AccessibleContext acc = [Link]();
if (acc == null) {
throw new RuntimeException("JLayer's AccessibleContext is null");
}
}
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


18
4. An Example (2/5)

/* @test

@summary Example1 - a simple testcase


@run main Example1
*/
§ Brief description of
import [Link].*;
the test.
import [Link].*;
§ Appear in output .jtr
public class Example1 { file
public static void main(String[] args) throws Exception {
JLayer l = new JLayer();
AccessibleContext acc = [Link]();
if (acc == null) {
throw new RuntimeException("JLayer's AccessibleContext is null");
}
}
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


19
4. An Example (3/5)

/* @test
@summary Example1 - a simple testcase
@run main Example1 § It means invoke main
*/ method of Example1 class
import [Link].*; § The line is optional for
import [Link].*; default execution.

public class Example1 {

public static void main(String[] args) throws Exception {


JLayer l = new JLayer();
AccessibleContext acc = [Link]();
if (acc == null) {
throw new RuntimeException("JLayer's AccessibleContext is null");
}
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
20
4. An Example (4/5)

/* @test
@summary Example1 - a simple testcase
§ Throw an exception to
@run main Example1
indicate test failure.
*/
§ Test should exit normally to
import [Link].*;
indicate PASS.
import [Link].*;

public class Example1 {


public static void main(String[] args) throws Exception {
JLayer l = new JLayer();
AccessibleContext acc = [Link]();
if (acc == null) {
throw new RuntimeException("JLayer's AccessibleContext is null");
}
}
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


21
4. Running an Example (5/5)

§ jtreg -verbose:summary -testjdk:{TESTJDK} [Link]


An empty file [Link] should exist at the root directory of the test.


Creates JTwork and JTreport directory, if the directory is not present.

§ JTreport/html/[Link] contains the overall results summary

§ JTreport/text/[Link] contains the results summary in text format

§ JTwork/[Link] contains test log file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


22
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


5. Log file (1/3)

#Test Results (version 2)


#Tue Nov 20 16:53:27 GMT 2012
#checksum:45cf21a8ef8efa
#-----testdescription-----
$file=/home/jtest/jtregtests/examples/[Link]
$root=/home/jtest/jtregtests
run=USER_SPECIFIED main Example1\n
source=[Link]
title=Example1 - a simple testcase Test information
#-----environment-----

#-----testresult-----
description=file\:/home/jtest/jtregtests/examples/[Link]
elapsed=928 0\:00\:00.928
end=Tue Nov 20 16\:53\:27 GMT 2012
environment=regtest
execStatus=Passed. Execution successful
hostname=testmachine Log file has an extension .jtr
javatestOS=Linux 2.6.32-100.28.5.el6.x86_64 (amd64)
javatestVersion=4.4 and can be found in sub-directories
jtregVersion=jtreg 4.1 fcs b04
script=[Link] of JTwork directory
sections=script_messages build compile main
start=Tue Nov 20 16\:53\:26 GMT 2012
test=examples/[Link]
[Link]=jtest
work=/home/jtest/jtregtests/JTwork/examples

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


24
5. Log file (2/3)

#Test Results (version 2)


#Tue Nov 20 16:53:27 GMT 2012
#checksum:45cf21a8ef8efa
#-----testdescription-----
$file=/home/jtest/jtregtests/examples/[Link]
$root=/home/jtest/jtregtests
run=USER_SPECIFIED main Example1\n
source=[Link]
title=Example1 - a simple testcase

#-----environment-----

#-----testresult-----
Test result summary
description=file\:/home/jtest/jtregtests/examples/[Link]
elapsed=928 0\:00\:00.928
end=Tue Nov 20 16\:53\:27 GMT 2012
environment=regtest
execStatus=Passed. Execution successful
hostname=testmachine
javatestOS=Linux 2.6.32-100.28.5.el6.x86_64 (amd64)
javatestVersion=4.4
jtregVersion=jtreg 4.1 fcs b04
script=[Link]
sections=script_messages build compile main
start=Tue Nov 20 16\:53\:26 GMT 2012
test=examples/[Link]
[Link]=jtest
work=/home/jtest/jtregtests/JTwork/examples

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


25
5. Log file (3/3)
#section:script_messages
----------messages:(4/184)----------
JDK under test: (/home/jtest/jdks/jdk1.8.0)
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b59)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b02, mixed mode)

#section:build
----------messages:(3/93)----------
command: build Example1
reason: Named class compiled on demand
elapsed time (seconds): 0.635
result: Passed. Build successful Detail test results broken
#section:compile
down into different phases
----------messages:(3/143)----------
command: compile /home/jtest/jtregtests/examples/[Link]
of test execution
reason: .class file out of date or does not exist
elapsed time (seconds): 0.631
----------[Link]:(0/0)----------
----------[Link]:(0/0)----------
result: Passed. Compilation successful

#section:main
----------messages:(3/102)----------
command: main Example1
reason: User specified action: run main Example1
elapsed time (seconds): 0.22
----------[Link]:(0/0)----------
----------[Link]:(1/15)----------
STATUS:Passed.
result: Passed. Execution successful

test result: Passed. Execution successful

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


26
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


1. Examples

§ Specifying VM Options

§ Applet testcase

§ Manual testcase

§ Shell test

§ Defining timeout

§ Reusing the testcase to run with different VM/GC options

§ Compiler test

§ Negative test

§ OS/Platform checks

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


28
1. Examples (1/9): Specifying VM options

/* @test
* @summary Example 2 - passing VM parameters
* @run main/othervm -Xms100m -Xmx100m -XX:+PrintGC -XX:
+UseParallelGC Example2
*/
public class Example2 {
§ VM options can be
public static void main(String[] args) throws InterruptedException {
….... specified with
for (GarbageCollectorMXBean collector : collectors) { main/othervm
String x = [Link](); § Equivalent to java <vm
if ([Link]("MarkSweep")) { options> Example2
long count = [Link]();
if (count > 0) {
throw new RuntimeException("Failed.”);
}
}
}
}
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


29
1. Examples (2/9) : Applet testcase
<html>
<!-- § Run the applet specified at
@test <APPLET> tag in
@summary - Example3 - running applet [Link]
@run applet [Link]
§ Equivalent to “appletviewer
-->
[Link]”
<head>
<title> Example3 </title>
</head>
<body>

<h1>Example3</h1>

<APPLET CODE="[Link]" WIDTH=200


HEIGHT=200></APPLET>
</body>
</html>

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


30
1. Examples (3/9): Manual testcase

<html>
<!-- § Run the applet specified at
@test <APPLET> tag in
@summary - Example4 - a manual test
[Link], but tester
@run applet/manual=yesno [Link]
need to interact and choose
whether test is pass or fail.
-->
<head> § NOTE: OpenJDK test
<title> Example4 - a manual test</title> workspace provides
</head> convenient helper classes to
<body>
display test instruction.

<h1> Example4 - a manual test</h1>

<APPLET CODE="[Link]" WIDTH=200


HEIGHT=200></APPLET>
</body>
</html>

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


31
1. Examples (4/9): Shell test

# @test
# @summary Example5 - shell tests
# @run shell [Link]

$TESTJAVA/bin/jar -tf "$TESTJAVA/jre/lib/[Link]" >


/dev/null 2>&1

if [ $? -ne 0 ]; then § Invokes the Bourne shell to


run [Link]
echo FAILED: [Link] file corrupt
exit 1
fi

exit 0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


32
1. Examples (5/9) : Defining timeout

/*
* @test
* @summary Example6 - interrupting loop/hang
* @run main/timeout=1 Example6
*/

public class Example6 {


public static void main(String[] args) throws
InterruptedException {
§ Invoke main method with
[Link]("Test Loop .... ");
timeout set in seconds.
for (int i = 0; i < 1000000000; i++) {
§ Test exit with Error if the
[Link](10);
execution takes longer than
} timeout period.
[Link]("Passed."); § Useful option to avoid test
} hangs.
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


33
1. Examples (6/9) : Reusing the testcase to run with
different VM/GC options
/* @test
* @summary Example7 - run tests with multiple java/vm flags
* @run main/othervm -client Example7 § Invoke main method multiple
* @run main/othervm -Xint Example7 times with different VM
* @run main/othervm -server Example7 options.
*/
§ Generates one output file (.jtr)
public class Example7 {
public static void main(String argv[]) { § Test fails if any one invocation
Integer x = new Integer(100); of main method fails.
Integer y = new Integer(100);

if ( ! [Link](y) ) {
throw new RuntimeException("Failed. x is not equal y");

if ([Link]() != [Link]()) {
throw new RuntimeException("Failed. Hashcode comparison failed.");
}
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
34
1. Examples (7/9) : Compiler test

/*
§ Invoke compiler and compiles
* @test
[Link]
* @summary Example8 - compile test
§ Test pass if compilation
* @compile [Link] succeeds.
*/ § Equivalent to “javac
[Link]”
public class Example8 {

static class Base<E> {}

static void test(Base<?> je) {


Object o = (Base<Integer>)je;
}
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


35
1. Examples (8/9) : Negative test

/*
* @test
* @summary Example9 - test pass if compilation fails
* @compile/fail [Link]
*/
§ Test pass if compilation fails
§ The option /fail can be used
public class Example9 { with main, applet and shell
void test(Float f, Integer i) { tests as well, but such use is
boolean b = f == i; discouraged
} ●
@run main/fail <test>
} ●
@run applet/fail <test>

@run shell/fail <test>

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


36
1. Examples (9/9) : OS/Platform checks

# @test § Write a wrapper shell test


# @summary Testing OS specific feature § Check OS name
# @run shell [Link] § Skip the test (pass) if the test is not
applicable
OS=`uname -s` § May use 'case' statement if test is
applicable to more than one OS.
if [ "$OS" != "Windows_NT" ]; then
§ NOTE: Such testcase filtering is not
echo "This is a Windows only test"
allowed if the feature is applicable
exit 0 to all OS/platforms.
fi

echo “run a test case”

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


37
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


2. Test Execution (1/3)

§ VM option from command line



jtreg -verbose:summary -testjdk:${TESTJDK} -ea -vmoption:"-XX:
+UseParallelGC" [Link]
§ Run all tests present in a directory

jtreg -verbose:summary -testjdk:${TESTJDK} ./examples
§ Run all manual tests in a directory

jtreg -verbose:summary -testjdk:${TESTJDK} -m ./examples
§ Run all tests with specific keyword

jtreg -verbose:summary -testjdk:${TESTJDK} -a -k:abc ./examples

[Link] file should contain a line “keys abc”

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


39
2. Test Execution (2/3)

§ Run all automated tests present in a directory



jtreg -verbose:summary -testjdk:${TESTJDK} -a ./examples
§ Running tests in concurrent mode

jtreg -verbose:summary -testjdk:${TESTJDK} -a -concurrency:auto
./examples

jtreg -verbose:summary -testjdk:${TESTJDK} -a -concurrency:2
./examples

Tests with /othervm can be run in concurrent mode
§ Increase time requirements to run a test

jtreg -verbose:summary -testjdk:${TESTJDK} -timeoutFactor:2
[Link]

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


40
2. Test Execution (3/3)

§ Excluding tests with known issues



jtreg -verbose:summary -testjdk:${TESTJDK} -a
-exclude:./[Link] ./examples
§ Re-running only the tests with error status in previous run

jtreg -verbose:summary -testjdk:${TESTJDK} -a -status:error,fail
./examples
§ There are many more options. Refer online help.

jtreg -h

jtreg -onlineHelp

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


41
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


3. TestNG tests
§ JTreg supports TestNG tests in two ways – Type A and Type B
§ Type A:


Write a testcase using TestNG

Add “[Link] = dir1 dir2” in [Link] or [Link] file, where, dir1
and dir2 represents a package root directory relative test root ([Link])
directory

[Link] file, if present, should be present at package root directory

While an individual testcase may include jtreg information tags such as @test or
@summary, it must not include jtreg action tags such as @run or @compile

§ Type B:


Write a testcase using TestNG

Add jtreg tags (e.g. @test) to the test source

Use “@run testng ..” tag instead of “@run main ..” tag

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


43
3. TestNG tests – Type A (1/2) [Link]
[Link] = .

OR
[Link]
[Link] = accessible

package [Link]

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


44
3. TestNG tests – Type A (2/2)
tests/acc/swing/[Link] tests/acc/swing/[Link]
package [Link]; package [Link];
import [Link].*; import [Link].*;
import [Link].*; import [Link].*;
import [Link]; import [Link];

@Test public class Example54 {


public class Example53 { @Test
public void testAccessibleJMenu() throws Exception { public void testAccessibleJMenuItem() throws Exception {
JMenu l = new JMenu(); JMenuItem l = new JMenuItem();
AccessibleContext acc = [Link](); AccessibleContext acc = [Link]();
if (acc == null) { if (acc == null) {
throw new RuntimeException("JMenu's AccessibleContext is null"); throw new RuntimeException("JMenuItem's AccessibleContext is null");
} }
} }
public void testAccessibleJMenuBar() throws Exception { @Test
JMenuBar l = new JMenuBar(); public void testAccessibleJFileChooser() throws Exception {
AccessibleContext acc = [Link](); JFileChooser l = new JFileChooser();
AccessibleContext acc = [Link]();
if (acc == null) {
if (acc == null) {

throw new RuntimeException("JMenuBar's AccessibleContext is null"); throw new RuntimeException("JFileChooser's AccessibleContext is


null");
}
}
}
}
}
}

No jtreg specific tags in the test source files


Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
45
3. TestNG tests – Type B

/* @test
@summary Example61 - a simple TestNG testcase that can be run under jtreg

@run testng Example61


*/

import [Link].*; @run testng action tag


import [Link].*;

import [Link];

public class Example61 {

@Test TestNG artifacts


public void testAccessibleContext() throws Exception {
JLayer l = new JLayer();
AccessibleContext acc = [Link]();
if (acc == null) {
throw new RuntimeException("JLayer's AccessibleContext is null");
}
}
}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


46
3. TestNG tests – specifying libraries
§ Specifying libraries in “Type 1” tests


Add “[Link] = dir1 dir2” to the [Link] file


If path starts with '/', the path is evaluated from the directory
containing [Link] file, else the path is evaluated from the
directory containing [Link] file

§ Specifying libraries in “Type 2” tests


Use @library tag <path>, it is same as in other jtreg tests


If path starts with '/', the path is evaluated from the directory
containing [Link] file, else the path is evaluated from the
directory relative to the testcase

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


47
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


1. How to Contribute?

§ Guidelines

[Link]

§ Subscribe to jtreg-use@[Link]

Ask general questions about jtreg use

§ Subscribe to jtreg-dev@[Link] and



Ask tough questions!


Send enhancement proposals

§ Subscribe to quality-discuss@[Link]

Discuss quality issues


Propose test cases, send change sets, send feedback etc.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


49
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


2. Recommended Practice

§ Modifying an existing testcase



Do not overwrite the test scenarios, unless existing test scenario is
obsolete with a new fix

§ Test case should run on Windows, Linux, Mac and Solaris.



No Exception


If testcase is not applicable to a OS/platform, make the testcase PASS.

§ Code review

Recommend two peer reviews


Send email to OpenJDK component mailing list for feedback

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


51
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


3. OpenJDK workspace (1/3)
§ Cloning OpenJDK workspace


$ hg clone [Link] localbuild


$ cd localbuild


$ sh get_source.sh

§ Test Root


${localbuild}/jdk/test


${localbuild}/langtools/test


${localbuild}/hotspot/test

§ [Link] present in “Test Root”

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


53
3. OpenJDK workspace (2/3)
§ A convenient 'Makefile' present in “Test Root”

Export environment variables

make CONCURRENCY=auto <target>
§ Environment Variables

$ export JT_HOME=<location of jtreg>


$ export JTREG=${JT_HOME}/<linux,solaris,win32>/bin/jtreg
$ export PRODUCT_HOME=<location of test jdk>
$ export ANT_HOME=<location of ant>
$ export PATH=${PATH}:${ANT_HOME}/bin
$ export ALT_OUTPUTDIR=<results home dir>
$ export JPRT_JTREG_HOME=${JT_HOME} // Required for langtools and hotspot
$ export JPRT_JAVA_HOME=<location of stable jdk> // Required for langtools
$ export JTREG_TESTDIRS=<location of langtools test> // Required for langtools
$ export TESTDIRS="compiler gc runtime serviceability" // Required for hotspot

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


54
3. OpenJDK workspace (3/3)
§ Executing langtool and hotspot tests

Export environment variables

make CONCURRENCY=auto jtreg-tests
§ Executing jdk tests

Export environment variables

make CONCURRENCY=auto jdk_nio1

make CONCURRENCY=auto jdk_nio2

make CONCURRENCY=auto jdk_lang

make CONCURRENCY=auto jdk_net

….....

make CONCURRENCY=auto jdk_all // Runs all jdk tests.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


55
Section I: Getting started Section II: Examples Section III: Contributing

[Link] [Link] 1. How to contribute?

[Link] and Bolts [Link] Execution 2. Recommended Practice

[Link] Execution [Link] tests 3. OpenJDK workspace

[Link] Example 4. References

[Link] file

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


References

§ [Link]

§ [Link]

§ [Link]

§ jtreg-dev@[Link]

§ FAQ included in jtreg bundle

§ [Link] included in jtreg bundle

§ jtreg -onlineHelp <word>

§ jtreg -help <word>

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.


57

You might also like