java Intellij 不运行测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34303792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Intellij does not run tests
提问by mherzl
After importing my project into Intellij and getting it to build successfully, I am trying to run some of my project's tests. I navigate to the test file and select Run -> Run. However, this does not run my tests, just opens a small "Edit Configurations" window, as the attached photo shows.
将我的项目导入 Intellij 并使其成功构建后,我正在尝试运行我的一些项目测试。我导航到测试文件并选择运行 -> 运行。但是,这不会运行我的测试,只是打开一个小的“编辑配置”窗口,如所附照片所示。
And, when I select Edit Configurations as prompted, JUnit is not to be found. The window is shown below.
而且,当我按照提示选择“编辑配置”时,找不到JUnit。窗口如下所示。
What do I need to do to run the tests?
我需要做什么来运行测试?
回答by rayen
回答by anon58192932
For me this was an issue with my pom.xml
and using JUnit5
with IntelliJ
because my tests were not getting detected and it said 0 executed 0 skipped
etc.
对我来说,这是我的问题pom.xml
,并使用JUnit5
与IntelliJ
因为并没有获得检测我的测试中,它说0 executed 0 skipped
等。
Here's what I added to my pom.xml
to get JUnit5
tests to run in IntelliJ
:
这是我添加到我pom.xml
的让JUnit5
测试运行的内容IntelliJ
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
And here's the dependencies I added:
这是我添加的依赖项:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0-M1</version>
</dependency>
</dependencies>
回答by Jac.
For me it was also an issue with my pom.xml. After checking Junit5-samples pom. I noticed the test plugin was missing. So I only needed to add:
对我来说,这也是我的 pom.xml 的问题。检查Junit5-samples pom 后。我注意到测试插件丢失了。所以我只需要添加:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
You may also want to check if your pom contains:
您可能还想检查您的 pom 是否包含:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>