通过VIM进行弹簧启动测试

发布于 2025-01-30 03:12:09 字数 149 浏览 1 评论 0原文

我安装了一个Mac和Iterm2,我使用了命令vi *文件名 *.java打开并编辑文件。该文件的单元测试在春季中使用@test关键字注释。

如何从命令行中运行这些测试,而不是单击Intellij中的测试注释?

I have a Mac and iTerm2 installed, I used the command vi *file name*.java to open and edit the file. This file has unit tests annotated with the @Test keyword in Spring.

How do I run these tests from the command line instead of clicking on the Test annotation in IntelliJ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2025-02-06 03:12:09

如果使用maven:
要运行所有测试用例,请进入项目的根并运行(如果从其他地方运行,请使用路径)

mvn test

从单个类中运行所有测试:

mvn test -Dtest=<YourTestClass>

从测试类中运行测试用例:

mvn test -Dtest=<name-of-your-test-class>#<name-of-your-test-method> test

如果您不使用Maven(或gradle):
请参阅:如何从命令行(没有Maven/Gradle)启动Junit 5(平台)?

edit :看起来OP无法在其设置中运行这些命令。确保您的POM中有正确的依赖关系和插件(Junit和surefire)。例如,我使用此POM创建了一个演示Maven项目(仅包括Junit和Surefire)。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M6</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

这是工作MVN测试命令的屏幕截图。

”在此处输入图像说明”

If using maven:
To run all test cases, go into the project's root and run (if running from somewhere else, use the path)

mvn test

To run all tests from a single class:

mvn test -Dtest=<YourTestClass>

To run a test case from a test class:

mvn test -Dtest=<name-of-your-test-class>#<name-of-your-test-method> test

If you are not using maven (or Gradle):
see: How to launch JUnit 5 (Platform) from the command line (without Maven/Gradle)?

EDIT: Looks like the OP is unable to run these commands in his/her setup. Make sure you have correct dependencies and plugins (Junit and SureFire) in your pom. E.g. I created a demo maven project with this pom (only including the Junit and Surefire).

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M6</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

Here are the screenshots of working mvn test commands.

enter image description here

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文