-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllTestRunnerLauncher.java
48 lines (43 loc) · 2.57 KB
/
AllTestRunnerLauncher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.oldboy;
/*
https://junit.org/junit5/docs/current/api/org.junit.platform.launcher/org/junit/platform/launcher/core/LauncherFactory.html
https://junit.org/junit5/docs/current/api/org.junit.platform.launcher/org/junit/platform/launcher/listeners/SummaryGeneratingListener.html
https://junit.org/junit5/docs/current/api/org.junit.platform.launcher/org/junit/platform/launcher/LauncherDiscoveryRequest.html
*/
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import java.io.PrintWriter;
public class AllTestRunnerLauncher {
public static void main(String[] args) {
/* Создаем ланчер */
Launcher firstLauncher = LauncherFactory.create();
/*
Поскольку мы пытаемся автоматизировать запуск всех наших
тестов нам нужно прослушивать модуль, который будет их
искать по указанному пути (способы указания пути различны)
И только через лиссенер мы можем посмотреть результаты
выполнения всех наших тестов (при желании вывести на экран).
*/
SummaryGeneratingListener summaryGeneratingListener =
new SummaryGeneratingListener();
/*
Наш ланчер поисковик ищет местоположение наших тестов,
мы указали пакет. Вариантов указания местоположения тестов
очень велико, вплоть до конкретного файла.
*/
LauncherDiscoveryRequest launcherDiscoveryRequest =
LauncherDiscoveryRequestBuilder.
request().
selectors(DiscoverySelectors.selectPackage("com.oldboy")).
build();
/* Запускаем все наши тесты из найденных */
firstLauncher.execute(launcherDiscoveryRequest, summaryGeneratingListener);
try(PrintWriter writeToScreen = new PrintWriter(System.out)){
summaryGeneratingListener.getSummary().printTo(writeToScreen);
}
}
}