主题问题可能会发生的常见原因,但这不是典型的情况。
我们在Junit4测试中有许多服务。我们正在研究升级平台的多个元素的过程,包括从Java 8移至Java 11,以及Junit 4至主要是Junit 5。
我正在研究我们已经努力转换的两种服务。在这两种情况下,我们都在Junit-Bom-5.8.2中使用所有工件,并且都使用Java 11。我们还使用Maven-Surefire-Plugin v3.0.0-M6。我们需要一个仅在该版本中可用的运行测试套件的修复程序。
在一项服务中,我们将许多测试从Junit 4转换为Junit 5,但并非全部。我们正在设法获得所有这些测试以取得成功。
在另一项服务中,所有测试都转换为Junit 5。在这种情况下,当我们从MVN运行测试时会发生奇怪的事情。它只是说:
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
我尝试使用“ -x”跑步。那没有告诉我任何有用的东西。
我们有一个“ UniteStsuite”类,其中包含我们单位测试类的全部或至少大多数。我从命令行运行。对于它试图在那里执行的每项测试,它都说:
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
它认为这是Junit 4测试的事实显然是一个线索,但我不知道这意味着什么。
请注意,我们正在加载的依赖项之一是 junit-vintage-engine
,但我们正在加载该服务,其中包括Chim Chimit 4和Junit 5测试的其他服务。
似乎该服务混合了Junit 4和Junit 5,它选择了每个服务的正确跑步者,但是如果该服务只有Junit 5测试,则仅选择Junit 4 Runner。
我们正在将老式引擎加载到父型POM中。我将努力构建一个不包括该版本的版本,以查看这是否是发生的,但是如果这确实是我们要做的,那将是一个很大的痛苦。
我经过了步骤,以确保未提供老式引擎,但没有改变任何东西。它仍然找不到任何可运行的方法。
例如,这是第一个测试类的摘录,它说它找不到任何可运行的方法:
...
import org.junit.jupiter.api.Test;
...
@SuppressWarnings("deprecation")
@ExtendWith(MockitoExtension.class)
@TestPropertySource(locations = "classpath:application-test.properties")
public class ...Test {
@InjectMocks
...
@Mock
private ...
...
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
...
}
@Test
public void getCrmResponse_success() throws Exception {
并再次注意,在 blockjunit4classrunner
class中,“无可运行的方法”例外发生了。 ,因此,对此使用什么Junit感到困惑。
我尝试添加一个虚拟Junit 4测试,这是它发现的唯一测试:
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) @ PlatformPilotMs ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running ...DummyTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.102 s - in ...DummyTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
There are common reasons why the subject question might be happening, but this is not a typical situation.
We had many services with working JUnit4 tests. We are working on a process of upgrading multiple elements of our platform, including moving from Java 8 to Java 11, and JUnit 4 to mostly JUnit 5.
I am looking at two services that we've worked on converting. In both cases, we are using all the artifacts in junit-bom-5.8.2, and both with Java 11. We are also using maven-surefire-plugin v3.0.0-M6. We need a fix for running test suites that is only available in that version.
In one service, we converted many of the tests from JUnit 4 to JUnit 5, but not all of them. We are managing to get all of these tests to succeed.
In another service, all of the tests were converted to JUnit 5. In that case, an odd thing happens when we run the tests from mvn. It simply says:
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
I tried running with "-X". That didn't tell me anything useful.
We have a "UnitTestSuite" class that contains all, or at least most, of our unit test classes. I ran that from the command line. For every test it tried to execute there, it said:
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
The fact that it thinks this is a JUnit 4 test is obviously a clue, but I don't know what it means.
Note that one of the dependencies we are loading is the junit-vintage-engine
, but we are loading that with the other service with mixed JUnit 4 and JUnit 5 tests.
It almost seems as if the service has mixed JUnit 4 and JUnit 5, it chooses the correct runner for each, but if the service ONLY has JUnit 5 tests, it only chooses the JUnit 4 runner.
We are loading the vintage engine in our parent pom. I will work on building a version that excludes that, just to see if that's what's happening, but that will be a big pain if that's really what we have to do.
I went through the steps to ensure that the vintage engine was not provided, but it didn't change anything. It's still failing to find any runnable methods.
For instance, here is a somewhat elided excerpt of the first test class that it says it can't find any runnable methods for:
...
import org.junit.jupiter.api.Test;
...
@SuppressWarnings("deprecation")
@ExtendWith(MockitoExtension.class)
@TestPropertySource(locations = "classpath:application-test.properties")
public class ...Test {
@InjectMocks
...
@Mock
private ...
...
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
...
}
@Test
public void getCrmResponse_success() throws Exception {
And note again, the "no runnable methods" exception occurs in the BlockJUnit4ClassRunner
class, so it's confused about what JUnit to use for this.
I tried adding a dummy JUnit 4 test, and this was the only test it found:
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) @ PlatformPilotMs ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running ...DummyTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.102 s - in ...DummyTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
发布评论
评论(1)
UOU将不得不告诉SureFire插件使用正确的测试提供商,对于Junit 5,Surefire-Junit-platform将
添加以下依赖项,以使Surefire插件选择Junit Jupiter。
参考:
Uou will have to tell Surefire plugin to use the correct test provider, for JUnit 5, it would be surefire-junit-platform
Add the following dependency for the Surefire plugin to select JUnit Jupiter.
Reference:
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/providers.html