Java 当JUnit测试失败时显示用户友好的消息

Java 当JUnit测试失败时显示用户友好的消息,java,junit,Java,Junit,我得到了这样的信息 com.controller.Test1 > test FAILED java.lang.NoSuchMethodError at Test1.java:18 测试编译的依赖项是 testCompile "junit:junit:4.11", 'org.mockito:mockito-all:1.10.19', 'com.jayway.jsonpath:json-path:2.2.0', 'org.hamcrest:ha

我得到了这样的信息

com.controller.Test1 > test FAILED
java.lang.NoSuchMethodError at Test1.java:18
测试编译的依赖项是

testCompile "junit:junit:4.11",
        'org.mockito:mockito-all:1.10.19',
        'com.jayway.jsonpath:json-path:2.2.0',
        'org.hamcrest:hamcrest-all:1.3',
        'org.flywaydb.flyway-test-extensions:flyway-dbunit-spring4-test:4.0'
这是我的测试代码

package com.controller;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;


@RunWith(MockitoJUnitRunner.class)
public class Test1 {

   @Test
   public void test(){
      assertThat(Long.valueOf(1), instanceOf(Integer.class));
    }
}
我想要这样的信息

com.controller.Test1 > test FAILED
java.lang.NoSuchMethodError at Test1.java:18
应为:java.lang.Integer的实例
但是:是java.lang.Long

java.lang.NoSuchMethodError与JUnit没有特别的关系。相反,它指示编译器类路径上的类版本与运行时类路径上的类版本不同


冲突的原因是JUnit自带了自己的
org.hamcrest.Matcher
类,而不是在代码中导入的类。在导入中使用
mockito core
而不是
mockito all
来排除匹配器。

使用
assertTrue(“messageifails”,condition)
?或
org.junit.Assert.assertThat(字符串、对象、匹配器)如何