hamcrest

【JUnit 报错】 method initializationerror not found:JUnit4单元测试报错问题

ぐ巨炮叔叔 提交于 2020-05-04 04:51:01
用JUnit测试一段代码,出现报错method initializationerror not found;出现如下问题: 双击这个就显示出现如下的错误: method 'initializationError' not found. 解决办法: 除了引入junit-4.12.jar之外,还要引入2个依赖jar包:hamcrest-core-1.3.rc2.jar,hamcrest-library-1.3.rc2.jar 引入jar包的方法: 点击 https://mvnrepository.com/(首先你得是maven项目可以这么引用) 搜索hamcrest-core,hamcrest-library,分别粘贴对应的标签到你的pom.xml 如粘贴 <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core --> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> <version>1.3</version> <scope>test</scope> </dependency> 到pom.xml中,如下: <project xmlns="http://maven.apache.org/POM

【转】Spring Boot快速入门

你离开我真会死。 提交于 2020-05-02 18:23:26
简介 在您第1次接触和学习Spring框架的时候,是否因为其繁杂的配置而退却了?在你第n次使用Spring框架的时候,是否觉得一堆反复黏贴的配置有一些厌烦?那么您就不妨来试试使用Spring Boot来让你更易上手,更简单快捷地构建Spring应用! Spring Boot让我们的Spring应用变的更轻量化。比如:你可以仅仅依靠一个Java类来运行一个Spring引用。你也可以打包你的应用为jar并通过使用java -jar来运行你的Spring Web应用。 Spring Boot的主要优点: 为所有Spring开发者更快的入门 开箱即用,提供各种默认配置来简化项目配置 内嵌式容器简化Web项目 没有冗余代码生成和XML配置的要求 快速入门 本章主要目标完成Spring Boot基础项目的构建,并且实现一个简单的Http请求处理,通过这个例子对Spring Boot有一个初步的了解,并体验其结构简单、开发快速的特性。 系统要求: Java 7及以上 Spring Framework 4.1.5及以上 本文采用 Java 1.8.0_73 、 Spring Boot 1.3.2 调试通过。 使用Maven构建项目 通过 SPRING INITIALIZR 工具产生基础项目 访问: http://start.spring.io/ 选择构建工具 Maven Project

intellij JUnit mockito

廉价感情. 提交于 2020-05-01 06:10:38
在intellij越来越普及的情况下,利用JUnit在intellij中进行测试就显得很基础了,但网上的资料总有误导的地方,这里记录一下。 总体而言,要开始单元测试,可以分为三步,添加相关的插件,添加相关的依赖,编写测试方法,下面依序说下。 一、添加相关的插件 在intellij中利用JUnit进行测试,需要三个插件,Junit,用来执行测试用例,JUnitGenerator V2.0,用来生成测试用例, Coverage, 用来生成测试报告。 安装插件完毕,还需要对JUnit进行适当的设置: Junit Generator设置 Setting --》 Other Setting--》 Junit Generator 更改输出路径, Output Path: ${SOURCEPATH}/../../test/java/${PACKAGE}/${FILENAME} 更改默认单元测试框架, Default Template: Junit 4 更改JUnit4的默认模板, Junit 4 test. $entry.packageName  $entry.packageName <pre>$date</pre>  <pre>$today</pre> 二,添加相关的依赖 在maven项目中,添加如下的依赖: <dependency> <groupId>junit</groupId>

Mockito 2 参数匹配器

你。 提交于 2020-02-28 12:43:46
Mockito 通过使用 equals() 这种自然的 Java 样式来校验参数值。有时候,当需要有其他一些灵活性的时候,你可能会要求使用参数匹配(argument matchers)。 请参考下面的代码: //stubbing using built-in anyInt() argument matcher when(mockedList.get(anyInt())).thenReturn( "element" ); //stubbing using custom matcher (let's say isValid() returns your own matcher implementation): when(mockedList.contains(argThat(isValid()))).thenReturn( "element" ); //following prints "element" System.out.println(mockedList.get( 999 )); //you can also verify using an argument matcher verify(mockedList).get(anyInt()); //argument matchers can also be written as Java 8 Lambdas verify

Intro to Spring Boot Starters

左心房为你撑大大i 提交于 2020-02-25 22:12:44
1. Overview Dependency management is a critical aspects of any complex project. And doing this manually is less than ideal; the more time you spent on it the less time you have on the other important aspects of the project. Spring Boot starters were built to address exactly this problem. Starter POMs are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy-paste loads of dependency descriptors. We have more than 30 Boot starters

Compilation error using Hamcrest everyItem()

可紊 提交于 2020-01-24 13:05:07
问题 I'm trying to use hasKey() on everyItem() in Hamcrest but I am getting the following compilation error: error: no suitable method found for assertThat(List<Map<String,Object>>,Matcher<Iterable<Map<? extends String,?>>>) assertThat(data, everyItem(hasKey("index"))); ^ method Assert.<T#1>assertThat(T#1,Matcher<? super T#1>) is not applicable (actual argument Matcher<Iterable<Map<? extends String,?>>> cannot be converted to Matcher<? super List<Map<String,Object>>> by method invocation

Why doesn't this code attempting to use Hamcrest's hasItems compile?

纵饮孤独 提交于 2020-01-19 03:08:48
问题 Why does this not compile, oh, what to do? import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.hasItems; ArrayList<Integer> actual = new ArrayList<Integer>(); ArrayList<Integer> expected = new ArrayList<Integer>(); actual.add(1); expected.add(2); assertThat(actual, hasItems(expected)); error copied from comment: cannot find symbol method assertThat(java.util.ArrayList<java.lang.Integer>, org.hamcreset.Matcher<java.lang.Iterable<java.util.ArrayList<java

junit and hamcrest declaration

我只是一个虾纸丫 提交于 2020-01-14 07:59:13
问题 I am using junit at 4.10 and declared hamcrest-core at 1.3 and hamcrest-library at 1.3. My question is are hamcrest-library and hamcrest-core embedded in junit 4.10. what about junit 4.11? <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> <version>1.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest<

Is there a version of JUnit assertThat which uses the Hamcrest 'describeMismatch' functionality?

蹲街弑〆低调 提交于 2020-01-13 09:37:05
问题 In every version of JUnit I have tried (up to 4.8.1), a failing assertThat will display an error message that looks like: expected: [describeTo] got: [String representation of object] In other words, it will display the toString() of the object instead of the mismatch description from the Matcher. If I use the assertThat from org.hamcrest.MatcherAssert.assertThat, then it will call 'describeMismatch' and display a more helpful error message. Am I using Junit incorrectly or is there currently

【Spring Boot 单元测试】1. 编写单元测试

≡放荡痞女 提交于 2020-01-06 23:26:35
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 编写单元测试可以帮助开发人员编写高质量的代码,提升代码质量,减少Bug,便于重构。Spring Boot提供了一些实用程序和注解,用来帮助我们测试应用程序,在Spring Boot中开启单元测试只需引入 spring-boot-starter-test 即可,其包含了一些主流的测试库。本文主要介绍基于 Service和Controller的单元测试。 引入 spring-boot-starter-test : <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> JUnit,标准的单元测试Java应用程序; Spring Test & Spring Boot Test,对Spring Boot应用程序的单元测试提供支持; Mockito, Java mocking框架,用于模拟任何Spring管理的Bean,比如在单元测试中模拟一个第三方系统Service接口返回的数据,而不会去真正调用第三方系统; AssertJ,一个流畅的assertion库