Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么命令行执行 #13

Open
poiu72 opened this issue Jul 25, 2021 · 2 comments
Open

怎么命令行执行 #13

poiu72 opened this issue Jul 25, 2021 · 2 comments

Comments

@poiu72
Copy link

poiu72 commented Jul 25, 2021

No description provided.

@houbb
Copy link
Owner

houbb commented Jul 25, 2021

这个应用设计的时候是为了写 junit 测试的开发者设计的。命令行执行的具体场景?

@Andyfoo
Copy link

Andyfoo commented Dec 28, 2023

这个应用设计的时候是为了写 junit 测试的开发者设计的。命令行执行的具体场景?

pom.xml add:
`

com.github.houbb
junitperf
2.0.7

	<!-- JUnit5单元测试框架 -->
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter-api</artifactId>
		<version>5.10.1</version>
	</dependency>
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter</artifactId>
		<version>5.10.1</version>
	</dependency>

	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter-engine</artifactId>
		<version>5.10.1</version>
	</dependency>
	<dependency>
		<groupId>org.junit.platform</groupId>
		<artifactId>junit-platform-commons</artifactId>
		<version>1.10.1</version>
	</dependency>
	<!-- 如果需要使用 JUnitPlatform Launcher API -->
	<dependency>
		<groupId>org.junit.platform</groupId>
		<artifactId>junit-platform-launcher</artifactId>
		<version>1.10.1</version>
	</dependency>`

Junit5TestPackageRunner.java
`
import org.junit.platform.engine.discovery.ClassNameFilter;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestPlan;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;

import lombok.extern.slf4j.Slf4j;

@slf4j
public class Junit5TestPackageRunner extends Junit5Runner implements Runnable {
private final String packageName;

public Junit5TestPackageRunner(String packageName) {
	this.packageName = packageName;
}

public void run() {
	log.info("Starting the package runner");
	LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
		.selectors(DiscoverySelectors.selectPackage(packageName))
		.filters(ClassNameFilter.includeClassNamePatterns(".*Tests"))
		.build();
	Launcher launcher = LauncherFactory.create();
	TestPlan plan = launcher.discover(request);
	launcher.registerTestExecutionListeners(getDefaultListener());
	launcher.execute(request);
}

}`

Junit5Runner.java
`import java.util.List;

import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;

public abstract class Junit5Runner {
private List<Class<?>> listeners;

public TestExecutionListener getDefaultListener() {
	return new SummaryGeneratingListener();
}

public void setListeners(List<Class<?>> listeners) {
	this.listeners = listeners;
}

}`

AppMain.java
`
import app.core.junit.Junit5TestPackageRunner;

public class AppMain {
public static void main(String[] args) {
new Junit5TestPackageRunner("app.tests").run();

}

}
`

打包后执行
jar中的 AppMain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants