Mockito терпит неудачу, когда junit3 находится на пути к классам - PullRequest
0 голосов
/ 02 ноября 2018

Я работаю над проектом, в котором много устаревших тестов junit3. Недавно мы перешли на JUnit 5 и запускаем старые тесты через junit-vintage. По нескольким причинам нам не удалось легко избавиться от зависимости junit3, поэтому она все еще находится в пути к классам (что пока не вызывает никаких проблем).

Проблемы возникают при использовании mockito.verify() в тесте, который улавливает разницу в аргументах:

public class TestTestTest {
    interface Foo {
        void frobnicate(int a);
    }

    @Test
    void testMockito() {
        Foo foo = mock(Foo.class);
        foo.frobnicate(42);
        verify(foo).frobnicate(43);
    }
}

Результаты в

java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    org/mockito/internal/junit/ExceptionFactory$JUnitArgsAreDifferent.create(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/AssertionError; @10: areturn
  Reason:
    Type 'org/mockito/exceptions/verification/junit/ArgumentsAreDifferent' (current frame, stack[0]) is not assignable to 'java/lang/AssertionError' (from method signature)
  Current Frame:
    bci: @10
    flags: { }
    locals: { 'java/lang/String', 'java/lang/String', 'java/lang/String' }
    stack: { 'org/mockito/exceptions/verification/junit/ArgumentsAreDifferent' }
  Bytecode:
    0x0000000: bb00 0259 2a2b 2cb7 0003 b0            


    at org.mockito.internal.junit.ExceptionFactory.canLoadJunitClass(ExceptionFactory.java:33)
    at org.mockito.internal.junit.ExceptionFactory.<clinit>(ExceptionFactory.java:12)
    at org.mockito.internal.exceptions.Reporter.argumentsAreDifferent(Reporter.java:313)
    at org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation(MissingInvocationChecker.java:43)
    at org.mockito.internal.verification.Times.verify(Times.java:37)
    at org.mockito.internal.verification.MockAwareVerificationMode.verify(MockAwareVerificationMode.java:27)
    at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:72)
    at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
    at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:35)
    at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:63)
    at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:49)
    at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptAbstract(MockMethodInterceptor.java:128)
    at test.TestTestTest$Foo$MockitoMock$448839763.setValue(Unknown Source)
    at test.TestTestTest.testMockito(TestTestTest.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:513)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
    at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:113)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:113)
    at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)

Основной причиной является ошибка компоновщика (ArgumentsAreDifferent - это junit4 AssertionError, но не junit3 AssertionError)

Есть ли обходной путь для этого, если я не могу избавиться от зависимости junit3?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...