【问题标题】:Dependencies for jUnit 4.11 with JMock 2.6 and Hamcrest 1.3jUnit 4.11 与 JMock 2.6 和 Hamcrest 1.3 的依赖关系
【发布时间】:2013-11-16 08:41:30
【问题描述】:

我正在使用 JUnit 4.8 JMock 2.5.1 和 Hamcrest 1.1 的组合。 现在我想用 JMock 2.6 和 Hamcrest 1.3 升级到 jUnit 4.11。

因为 JUnit 4.11 附带 hamcrest 1.3。 我只通过依赖管理导入 JUnit 4.11 和 JMock。

依赖 org="org.jmock" name="jmock-legacy" rev="2.6.0" conf="test->" transitive="true" 依赖 org="org.jmock" name="jmock-junit4" rev="2.6.0" conf="test->" transitive="true"

依赖 org="junit" name="junit" rev="4.11" conf="test->default"

但是我在这种组合中运行我的测试时遇到了奇怪的行为,例如:

java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy7.getAssignedPermissionValues(Unknown Source)
at permissions.xml.UserRolePermissionsTest$2.<init>(UserRolePermissionsTest.java:80)
at permissions.xml.UserRolePermissionsTest.emptyPermissionInfosAreSilentlyIgnoredByConstructor(UserRolePermissionsTest.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.jmock.integration.junit4.JUnitRuleMockery$1.evaluate(JUnitRuleMockery.java:49)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.InstantiationException: java.util.EnumSet
at java.lang.Class.newInstance(Class.java:359)
at org.jmock.internal.ReturnDefaultValueAction.collectionOrMapInstanceFor(ReturnDefaultValueAction.java:87)
at org.jmock.internal.ReturnDefaultValueAction.invoke(ReturnDefaultValueAction.java:77)
at org.jmock.internal.InvocationToExpectationTranslator.invoke(InvocationToExpectationTranslator.java:20)
at org.jmock.internal.FakeObjectMethods.invoke(FakeObjectMethods.java:38)
at org.jmock.lib.JavaReflectionImposteriser$1.invoke(JavaReflectionImposteriser.java:33)
... 28 more

有人可以提供我需要的正确依赖项吗?或者解释一下我做错了什么。

问候和感谢

【问题讨论】:

    标签: junit jmock hamcrest


    【解决方案1】:

    这对我有用:如果我没记错的话,jmock-junit4 将引入 junit-dep:4.4(不会与 junit:4.11 省略,artifactId 不同)。

    <!-- general test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>hamcrest-core</artifactId>
                    <groupId>org.hamcrest</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3.RC2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jmock</groupId>
            <artifactId>jmock-junit4</artifactId>
            <version>2.6.0</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>hamcrest-core</artifactId>
                    <groupId>org.hamcrest</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>junit-dep</artifactId>
                    <groupId>junit</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多