Package org.junit.runner
Class JUnitCore
- java.lang.Object
-
- org.junit.runner.JUnitCore
-
public class JUnitCore extends java.lang.Object
JUnitCore
is a facade for running tests. It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures. To run tests from the command line, runjava org.junit.runner.JUnitCore TestClass1 TestClass2 ...
. For one-shot test runs, use the static methodrunClasses(Class[])
. If you want to add special listeners, create an instance ofJUnitCore
first and use it to run the tests.- Since:
- 4.0
- See Also:
Result
,RunListener
,Request
-
-
Field Summary
Fields Modifier and Type Field Description private RunNotifier
notifier
-
Constructor Summary
Constructors Constructor Description JUnitCore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(RunListener listener)
Add a listener to be notified as the tests run.(package private) static Computer
defaultComputer()
java.lang.String
getVersion()
static void
main(java.lang.String... args)
Run the tests contained in the classes named in theargs
.void
removeListener(RunListener listener)
Remove a listener.Result
run(java.lang.Class<?>... classes)
Run all the tests inclasses
.Result
run(Test test)
Run all the tests contained in JUnit 3.8.xtest
.Result
run(Computer computer, java.lang.Class<?>... classes)
Run all the tests inclasses
.Result
run(Request request)
Run all the tests contained inrequest
.Result
run(Runner runner)
Do not use.static Result
runClasses(java.lang.Class<?>... classes)
Run the tests contained inclasses
.static Result
runClasses(Computer computer, java.lang.Class<?>... classes)
Run the tests contained inclasses
.(package private) Result
runMain(JUnitSystem system, java.lang.String... args)
-
-
-
Field Detail
-
notifier
private final RunNotifier notifier
-
-
Method Detail
-
main
public static void main(java.lang.String... args)
Run the tests contained in the classes named in theargs
. If all tests run successfully, exit with a status of 0. Otherwise exit with a status of 1. Write feedback while tests are running and write stack traces for all failed tests after the tests all complete.- Parameters:
args
- names of classes in which to find tests to run
-
runClasses
public static Result runClasses(java.lang.Class<?>... classes)
Run the tests contained inclasses
. Write feedback while the tests are running and write stack traces for all failed tests after all tests complete. This is similar tomain(String[])
, but intended to be used programmatically.- Parameters:
classes
- Classes in which to find tests- Returns:
- a
Result
describing the details of the test run and the failed tests.
-
runClasses
public static Result runClasses(Computer computer, java.lang.Class<?>... classes)
Run the tests contained inclasses
. Write feedback while the tests are running and write stack traces for all failed tests after all tests complete. This is similar tomain(String[])
, but intended to be used programmatically.- Parameters:
computer
- Helps construct Runners from classesclasses
- Classes in which to find tests- Returns:
- a
Result
describing the details of the test run and the failed tests.
-
runMain
Result runMain(JUnitSystem system, java.lang.String... args)
- Parameters:
system
-args
- from main()
-
getVersion
public java.lang.String getVersion()
- Returns:
- the version number of this release
-
run
public Result run(java.lang.Class<?>... classes)
Run all the tests inclasses
.- Parameters:
classes
- the classes containing tests- Returns:
- a
Result
describing the details of the test run and the failed tests.
-
run
public Result run(Computer computer, java.lang.Class<?>... classes)
Run all the tests inclasses
.- Parameters:
computer
- Helps construct Runners from classesclasses
- the classes containing tests- Returns:
- a
Result
describing the details of the test run and the failed tests.
-
run
public Result run(Request request)
Run all the tests contained inrequest
.- Parameters:
request
- the request describing tests- Returns:
- a
Result
describing the details of the test run and the failed tests.
-
run
public Result run(Test test)
Run all the tests contained in JUnit 3.8.xtest
. Here for backward compatibility.- Parameters:
test
- the old-style test- Returns:
- a
Result
describing the details of the test run and the failed tests.
-
addListener
public void addListener(RunListener listener)
Add a listener to be notified as the tests run.- Parameters:
listener
- the listener to add- See Also:
RunListener
-
removeListener
public void removeListener(RunListener listener)
Remove a listener.- Parameters:
listener
- the listener to remove
-
defaultComputer
static Computer defaultComputer()
-
-