Discovery Selectors

The JUnit Platform provides a rich set of discovery selectors that can be used to specify which tests should be discovered or executed.

Discovery selectors can be created programmatically using the factory methods in the DiscoverySelectors class, specified declaratively via annotations when using the JUnit Platform Suite Engine, via options of the Console Launcher, or generically as strings via their identifiers.

The following discovery selectors are provided out of the box:

Java Type API Annotation Console Launcher Identifier

ClasspathResourceSelector

selectClasspathResource

@SelectClasspathResource

--select-resource /foo.csv

resource:/foo.csv

ClasspathRootSelector

selectClasspathRoots

 — 

--scan-classpath bin

classpath-root:bin

ClassSelector

selectClass

@SelectClasses

--select-class com.acme.Foo

class:com.acme.Foo

DirectorySelector

selectDirectory

@SelectDirectories

--select-directory foo/bar

directory:foo/bar

FileSelector

selectFile

@SelectFile

--select-file dir/foo.txt

file:dir/foo.txt

IterationSelector

selectIteration

@Select("<identifier>")

--select-iteration method=com.acme.Foo#m[1..2]

iteration:method:com.acme.Foo#m[1..2]

MethodSelector

selectMethod

@SelectMethod

--select-method com.acme.Foo#m

method:com.acme.Foo#m

ModuleSelector

selectModule

@SelectModules

--select-module com.acme

module:com.acme

NestedClassSelector

selectNestedClass

@Select("<identifier>")

--select <identifier>

nested-class:com.acme.Foo/Bar

NestedMethodSelector

selectNestedMethod

@Select("<identifier>")

--select <identifier>

nested-method:com.acme.Foo/Bar#m

PackageSelector

selectPackage

@SelectPackages

--select-package com.acme.foo

package:com.acme.foo

UniqueIdSelector

selectUniqueId

@Select("<identifier>")

--select-unique-id <identifier>

uid:[engine:Foo]/[segment:Bar]

UriSelector

selectUri

@SelectUris

--select-uri file:///foo.txt

uri:file:///foo.txt