首页 > TAG信息列表 > Hamcrest

Hamcrest使用

简介 Hamcrest支持多种语言,是可以自定义匹配器对象的框架,可以更灵活的定义“匹配”规则,在很多情况下匹配器都是很好用的,比如UI校验、数据过滤,尤其在测试方面进行断言,之前用的最多的就是assert了,Hamcrest使用起来会更加的灵活。下面已python为例进行介绍。 安装 `pip install Pyh

python测试框架之pytest (三)断言

一、pytest断言 Pytest中断言是通过 assert 语句实现的,确定预期值和实际值是否一致。 1.1、pytest等值类型断言 import allure class TestAssert: @allure.story("pytest-assert方式") def test_equals(self): the_biscuit = "Ginger" my_biscuit

MyBatis学习之运行测试方法时出现java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误(原因及解决方法)

MyBatis学习之运行测试方法时出现java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误(原因及解决方法) 错误原因:junit是4.11版本,从4.11版本起,junit中不再包含hamcrest的jar包 解决方案:手动在pom.xml中添加hamcrest-core-1.3.jar <dependency> <groupId>org.ha

单元测试包junit报错 java.lang.NoClassDefFoundError

junit 单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing_u011954243的博客-CSDN博客 报错的原因是junit4.10之后的版本不能单独引入junit 需要连带着引入hamcrest-core-1.3包或者降低junit版本到junit4.10

单元测试包junit报错 java.lang.NoClassDefFoundError

junit 单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing_u011954243的博客-CSDN博客 报错的原因是junit4.10之后的版本不能单独引入junit 需要连带着引入hamcrest-core-1.3包或者降低junit版本到junit4.10

如何用JUnit单元测试List

问题 JUnit测试List时差强人意。 解法 引入依赖 hamcrest-library包含许多有用方法来测试List数据类型。 <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</sc

JUnit4---Hamcrest匹配器常用方法总结

JUnit4---Hamcrest匹配器常用方法总结 neven7 2015-01-07 16:49:20  5323  收藏 5 分类专栏: junit 版权 一.Hamcrest是什么? Hamcrest is a library of matchers, which can be combined in to create flexible expressions of intent in tests. Hamcrest 是

method 'initializationError' not found: Opening the test classs

Junit4单元测试报错:method 'initializationError' not found: Opening the test classs 1.缺包 除了junit还需要hamcrest-core和hamcrest-library。 下载:https://mvnrepository.com/ 2.包版本不对 junit-4.13.jar,对应可以用网上大家普遍用的 hamcrest-core-1.3.jar和hamcrest-libr

java-Iterable的自定义匹配器的正确签名是什么?

我正在尝试为具有Iterable字段的类编写自定义匹配器.我无法找到一种方法来使其可以接受任何匹配项everyItem,hasItem和contains-因为每个匹配项都返回略有不同的泛型类型.做这个的最好方式是什么? 这是一个简单的示例来演示该问题-如何进行编译?我正在使用Hamcrest 1.3. import stat

java-Hamcrest中的stringContainsInAnyOrder匹配项?

Hamcrest中有一个StringContainsInOrder Matcher. 我如何断言一个字符串包含任何顺序的字符串集合?解决方法:您可以组合多个包含匹配器. assertThat("this is a string", allOf( contains("string"), contains("this"), contains("a")));

java-将lambdaj与String.matches方法一起使用

如何过滤Collection< String>使用lambdaj和String.matches方法. 我是lambdaj的新手,并且感到愚蠢,因为给出的示例比这更复杂.解决方法:如果可以使用hading(on(…))构造函数进行调用,则调用可能如下所示: select(collection, having( on(String.class).matches("f*") )) 但不幸的是

Java泛型和通配符:如何使此代码编译?

我正在使用Hamcrest 1.2库编写一些匹配器,但Java通配符却很难.当我尝试编译以下代码时 public class GenericsTest { public void doesNotCompile() { Container<String> container = new Container<String>(); // this is the desired assertion syntax

java – 如何使用Hamcrest检查双精度数组中的每个元素是否“接近”另一个数组中的每个元素?

我想比较两个双打阵列.使用vanilla JUnit,我可以这样做: double[] a = new double[]{1.0, 2.0, 3.0}; double[] b = new double[]{1.0, 2.0, 3.0}; assertEquals(a, b, 1e-10); 我想知道如何使用Hamcrest,最好不要创建自定义匹配器(如果可能).类似于为数组中的每个元素使用“close

java – 如何断言列表至少有n个大于x的项(在junit中使用hamcrest)

我可以使用以下代码检查列表是否有一个大于30的项目. //Using Hamcrest List<Integer> ints= Arrays.asList(22,33,44,55); assertThat(ints,hasItem(greaterThan(30))); 但是,如果列表中至少有2个项目大于30,我怎么断言呢? 有了AssertJ,我知道有一个解决方案.但我不知道如何用Ham

java – 为什么我的hamcrest“包含”不按预期工作?

我运行这一行: List<String> ids = new List<String>() ids.add("id1"); ids.add("id2"); assertThat(ids, contains("id1")); 但奇怪的是它返回“失败”. 我怎样才能解决这个问题?解决方法:你需要使用 assertThat(ids, hasItem(equalTo("id1")); 这是因为conta

android – Espresso测试,ImageView包含一个drawable

我从his medium post开始实现Daniele Bottilo的Drawable匹配器. 现在我想用它来测试我的图像视图是不是空的.我试过这个: onView(withId(R.id.image)) .check( matches( not(noDrawable()) ) ); 它不起作用,IDE警告我 not(…guava.base.Predicate) in Predicates canno

java – hamcrest核心,为什么需要这个?

我在Java中使用JUnit作为我的TDD,并注意到有两个组件可以从JUnit.org下载.首先,我认为我需要JUnit组件并下载,安装.当我编译并尝试运行我的测试时,它抱怨没有找到Hamcrest类.所以我不得不从他们的主页再次下载这个. 因此,出于好奇,为什么我们需要从一开始就为一个目的使用两次下载?

java – 如何验证该数组包含放心的对象?

例如,我有JSON作为回应: [{"id":1,"name":"text"},{"id":2,"name":"text"}]} 我想验证响应是否包含自定义对象.例如: Person(id=1, name=text) 我找到了解决方案 Person[] persons = response.as(Person[].class); assertThat(person, IsArra

java – Hamcrest assertThat – 类型推断

这是我的一个项目中正在完成的简化版本: List<String> names = ... assertThat(names, is(empty())); 这在我在Java 1.7.0.79(以及1.6.0.31)上运行的Eclipse上运行得很好. 但是,在使用Java 1.7.0.55(和1.6.0.29)的远程系统上编译失败,这是错误消息: no suitable method found for

如何断言Set具有与hamcrest具有精确属性的项目

我一直在尝试使用这个solution断言我的Set有给定属性的集合,使用这个solution,但我有: java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V at org.hamcrest.Condition$Matched.matching(Condition.java

android – Espresso检查视图是否isExotExist isDisplayed

以下语句不起作用,因为doesNotExist()返回ViewAssertion而不是匹配器.没有try-catch的任何方式使它工作? .check(either(matches(doesNotExist())).or(matches(not(isDisplayed())))); 解决方法:我有同样的问题,我的一个观点最初没有某个视图,但可以添加它并稍后隐藏它.用户界面依

java – 使用Mockito进行谓词时“OR”匹配器的问题

我想做这个: when(myObject.getEntity(1l,usr.getUserName()).thenReturn(null); when(myObject.getEntity(1l,Constants.ADMIN)).thenReturn(null); 在一线与匹配.所以,我有这个代码: import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import static

java – 用于比较超类和子类的Hamcrest匹配器

我有以下课程: abstract class Answer<T> {} class AnswerInt extends Answer<Integer> {} class AnswerText extends Answer<String> {} 现在我想在下面的测试中使用Hamcrest Matcher(它只是简化的例子): @Test public void test() { Answer a = new AnswerInt(5); asser

java – 递归SamePropertyValues作为hamcrest中的匹配器

我正在寻找一个与SamePropertyValuesAs行为相同的hamcrest匹配器但是如果一个属性不是原始的,标准Java类之一(字符串,整数等),或其中一个的复合(集合)或者数组)然后它也将对这些属性进行递归匹配. 那里有这样的匹配器还是我必须自己动手?解决方法:现在可以通过Shazam(我工作的地方)

php – Mockery:测试参数是否是包含键/值对的数组

我如何使用mockery和hamcrest断言当调用模拟对象的方法时,传递给它的一个参数是一个包含键/值对的数组? 例如,我的测试代码可能如下所示: $mock = m::mock('\Jodes\MyClass'); $mock ->shouldReceive('myMethod') ->once() ->with( arrayCon