Maven 为测试用例构建 JAR
我使用 Maven 在 Eclipse 上有 Spring Boot Selenium Web 驱动程序项目。我在 scr/test/java
中运行测试,并将所有元素、页面、配置放入 scr/main/java
中。
现在我想创建可执行的jar。怎么办?是否可以?我希望它像 java -jar mytask.jar
一样从 cmd 运行,
到目前为止我尝试使用 mvn clean install、mvn clean package 来生成 .jar 文件。但是当我尝试运行它时,它不起作用。它在 scr/main/java
中运行 main。我想在 scr/test/java 中运行,
这是我的测试类:
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.bca.magenta.pages.HomePage;
@SpringBootTest
class ApplicationTests {
@Autowired
HomePage homePage;
@Autowired
WebDriver driver;
@BeforeEach
public void before() {
driver.manage().window().maximize();
}
@Test
public void test() throws InterruptedException {
homePage.testInsert();
}
@AfterEach
public void after() {
driver.quit();
}
}
当我在 eclipse 中作为 junit 运行时,这是我在 src/main/java 中的主类
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
。它按我的预期运行。但如何在 jar 中运行它?
i have spring boot selenium web driver project on eclipse using maven. i run the test in scr/test/java
and put all element, pages, configuration in scr/main/java
.
now i want to create executable jar. how to do this? is it possible? i want it to run from cmd like java -jar mytask.jar
so far i tried using mvn clean install, mvn clean package to generate .jar file. but when i tried to run it, it doesn't work. it runs the main in scr/main/java
. i want to run in scr/test/java
this is my test class:
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.bca.magenta.pages.HomePage;
@SpringBootTest
class ApplicationTests {
@Autowired
HomePage homePage;
@Autowired
WebDriver driver;
@BeforeEach
public void before() {
driver.manage().window().maximize();
}
@Test
public void test() throws InterruptedException {
homePage.testInsert();
}
@AfterEach
public void after() {
driver.quit();
}
}
this is my main class in src/main/java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
when i run in eclipse as junit. it run as i expected. but how to run this in jar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 shade 插件,这是一个 示例:
Use the shade plugin, here's an example: