Join us for ⁠#Android11: The Beta Launch Show on June 3!
Added in API level 1

TestSuite

open class TestSuite : Test
kotlin.Any
   ↳ junit.framework.TestSuite

A TestSuite is a Composite of Tests. It runs a collection of test cases. Here is an example using the dynamic test definition.

TestSuite suite= new TestSuite();
  suite.addTest(new MathTest("testAdd"));
  suite.addTest(new MathTest("testDivideByZero"));
  

Alternatively, a TestSuite can extract the tests to be run automatically. To do so you pass the class of your TestCase class to the TestSuite constructor.

TestSuite suite= new TestSuite(MathTest.class);
  

This constructor creates a suite with all the methods starting with "test" that take no arguments.

A final option is to do the same for a large array of test classes.

Class[] testClasses = { MathTest.class, AnotherTest.class }
  TestSuite suite= new TestSuite(testClasses);
  

Summary

Public constructors

Constructs an empty TestSuite.

<init>(theClass: Class<*>!)

Constructs a TestSuite from the given class.

<init>(theClass: Class<out TestCase!>!, name: String!)

Constructs a TestSuite from the given class with the given name.

<init>(name: String!)

Constructs an empty TestSuite.

<init>(vararg classes: Class<*>!)

Constructs a TestSuite from the given array of classes.

<init>(classes: Array<Class<out TestCase!>!>!, name: String!)

Constructs a TestSuite from the given array of classes with the given name.

Public methods

open Unit
addTest(test: Test!)

Adds a test to the suite.

open Unit
addTestSuite(testClass: Class<out TestCase!>!)

Adds the tests from the given class to the suite

open Int

Counts the number of test cases that will be run by this test.

open static Test!
createTest(theClass: Class<*>!, name: String!)

.

open String!

Returns the name of the suite.

open static Constructor<*>!
getTestConstructor(theClass: Class<*>!)

Gets a constructor which takes a single String as its argument or a no arg constructor.

open Unit
run(result: TestResult!)

Runs the tests and collects their result in a TestResult.

open Unit
runTest(test: Test!, result: TestResult!)

open Unit
setName(name: String!)

Sets the name of the suite.

open Test!
testAt(index: Int)

Returns the test at the given index

open Int

Returns the number of tests in this suite

open Enumeration<Test!>!

Returns the tests as an enumeration

open String

open static Test!
warning(message: String!)

Returns a test which will fail and log a warning message.

Public constructors

<init>

Added in API level 1
TestSuite()

Constructs an empty TestSuite.

<init>

Added in API level 1
TestSuite(theClass: Class<*>!)

Constructs a TestSuite from the given class. Adds all the methods starting with "test" as test cases to the suite. Parts of this method were written at 2337 meters in the Hueffihuette, Kanton Uri

<init>

Added in API level 1
TestSuite(
    theClass: Class<out TestCase!>!,
    name: String!)

Constructs a TestSuite from the given class with the given name.

<init>

Added in API level 1
TestSuite(name: String!)

Constructs an empty TestSuite.

<init>

Added in API level 16
TestSuite(vararg classes: Class<*>!)

Constructs a TestSuite from the given array of classes.

Parameters
classes Class<*>!: TestCases

<init>

Added in API level 16
TestSuite(
    classes: Array<Class<out TestCase!>!>!,
    name: String!)

Constructs a TestSuite from the given array of classes with the given name.

Public methods

addTest

Added in API level 1
open fun addTest(test: Test!): Unit

Adds a test to the suite.

addTestSuite

Added in API level 1
open fun addTestSuite(testClass: Class<out TestCase!>!): Unit

Adds the tests from the given class to the suite

countTestCases

Added in API level 1
open fun countTestCases(): Int

Counts the number of test cases that will be run by this test.

createTest

Added in API level 1
open static fun createTest(
    theClass: Class<*>!,
    name: String!
): Test!

...as the moon sets over the early morning Merlin, Oregon mountains, our intrepid adventurers type...

getName

Added in API level 1
open fun getName(): String!

Returns the name of the suite. Not all test suites have a name and this method can return null.

getTestConstructor

Added in API level 1
open static fun getTestConstructor(theClass: Class<*>!): Constructor<*>!

Gets a constructor which takes a single String as its argument or a no arg constructor.

run

Added in API level 1
open fun run(result: TestResult!): Unit

Runs the tests and collects their result in a TestResult.

runTest

Added in API level 1
open fun runTest(
    test: Test!,
    result: TestResult!
): Unit

setName

Added in API level 1
open fun setName(name: String!): Unit

Sets the name of the suite.

Parameters
name String!: the name to set

testAt

Added in API level 1
open fun testAt(index: Int): Test!

Returns the test at the given index

testCount

Added in API level 1
open fun testCount(): Int

Returns the number of tests in this suite

tests

Added in API level 1
open fun tests(): Enumeration<Test!>!

Returns the tests as an enumeration

toString

Added in API level 1
open fun toString(): String
Return
String a string representation of the object.

warning

Added in API level 16
open static fun warning(message: String!): Test!

Returns a test which will fail and log a warning message.