import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.both;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.everyItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import java.util.Arrays; import org.hamcrest.core.CombinableMatcher;
import org.junit.Test; public class AssertTests {
@Test
public void testAssertArrayEquals() {
byte[] expected = "trial".getBytes();
byte[] actual = "trial".getBytes();
assertArrayEquals("failure - byte arrays not same", expected, actual);
} @Test
public void testAssertEquals() {
assertEquals("failure - strings are not equal", "text", "text");
} @Test
public void testAssertFalse() {
assertFalse("failure - should be false", false);
} @Test
public void testAssertNotNull() {
assertNotNull("should not be null", new Object());
} @Test
public void testAssertNotSame() {
assertNotSame("should not be same Object", new Object(), new Object());
} @Test
public void testAssertNull() {
assertNull("should be null", null);
} @Test
public void testAssertSame() {
Integer aNumber = Integer.valueOf(768);
assertSame("should be same", aNumber, aNumber);
} // JUnit Matchers assertThat
@Test
public void testAssertThatBothContainsString() {
assertThat("albumen", both(containsString("a")).and(containsString("b")));
} @Test
public void testAssertThatHasItems() {
assertThat(Arrays.asList("one", "two", "three"), hasItems("one", "three"));
} @Test
public void testAssertThatEveryItemContainsString() {
assertThat(Arrays.asList(new String[] { "fun", "ban", "net" }), everyItem(containsString("n")));
} // Core Hamcrest Matchers with assertThat
@Test
public void testAssertThatHamcrestCoreMatchers() {
assertThat("good", allOf(equalTo("good"), startsWith("good")));
assertThat("good", not(allOf(equalTo("bad"), equalTo("good"))));
assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
assertThat(7, not(CombinableMatcher.<Integer> either(equalTo(3)).or(equalTo(4))));
assertThat(new Object(), not(sameInstance(new Object())));
} @Test
public void testAssertTrue() {
assertTrue("failure - should be true", true);
}
}

Junit 的Assertions的使用的更多相关文章

  1. JUnit5学习之三:Assertions类

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  2. jmockit学习

    下图为jmockit 类图.在我们编写代码时几乎都会用到Expectations(期望)和Verifications(校验),二者均继承自Invacations. 常会用到的注解有:@Mocked @ ...

  3. JUnit5 技术前瞻

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6868495.html   JUnit ...

  4. Forget Guava: 5 Google Libraries Java Developers Should Know

    Forget Guava: 5 Google Libraries Java Developers Should Know Published on 2016 7 13 Somenath PandaFo ...

  5. Spock - Document -02 - Spock Primer

    Spock Primer Peter Niederwieser, The Spock Framework TeamVersion 1.1 This chapter assumes that you h ...

  6. 单元测试系列之六:JUnit5 技术前瞻

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6868495.html   JUnit ...

  7. RunningCassandraInEclipse(转载)

    转载自:http://wiki.apache.org/cassandra/RunningCassandraInEclipse Eclipse is open source. Download Ecli ...

  8. 五年了,你还在用Junit4吗?

    junit5 JUnit5在2017年就发布了,你还在用junit4吗? 什么是junit5 与以前的JUnit版本不同,JUnit 5由三个不同子项目的多个不同模块组成. JUnit 5 = JUn ...

  9. How to Use JUnit With JMeter

    Do you need to use JUnit in your testing processes? To answer this question, let's take a look first ...

随机推荐

  1. 关于随机数、方法重载和System.out.println()的认识

    (1)使用纯随机数发生器编写一个指定数目内数字的程序(类真随机数) 源代码: package Demo1; public class trueRandom { long Multiplier = 45 ...

  2. vue中使用echarts

    1.下载依赖 cnpm i echarts -S 2.模块中引入 <template> <div class="analyzeSystem"> <di ...

  3. 关于Python veriable scope 的一点疑问

    在写程序中遇到了类似于以下代码的问题: #不会报错 a=1 def f(): print(a) f() #会报错 a=1 def f(): a+=1 f()

  4. 《大话设计模式》c++实现 外观模式

    外观模式:为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 外观模式在什么时候使用呢? 分为三个阶段: (1)首先,在设计初期阶段,应该要有意识的 ...

  5. Lua 可变参数之arg与select

    function TestFunc(...) local arg = { ... } --Lua .2以后不再支持默认arg参数,{}与...之间要有空格 print("输入的参数个数:&q ...

  6. Object-C-Foundation-反射

    主要方法和类型 Class 变量名 = [类或者对象 class]; Class 变量名  = [类或者对象 superclass]; Class 变量名  = NSClassFromString(方 ...

  7. uva 10163 Storage Keepers

    题意: 有n个仓库,m个人,一个仓库只能由一个人托管,每个人可以托管多个仓库. 每个人有一个能力值a,如果说他托管了k个仓库,那么这些仓库的安全值都是a/k. 雇佣一个人的花费也是a. 如果一个仓库没 ...

  8. sql 表中删除字段重复的行

    Id    Email    UserName1    Taiseer.Joudeh@hotmail.com    TaiseerJoudeh2    Hasan.Ahmad@mymail.com   ...

  9. Spark学习之路 (五)Spark伪分布式安装

    一.JDK的安装 JDK使用root用户安装 1.1 上传安装包并解压 [root@hadoop1 soft]# tar -zxvf jdk-8u73-linux-x64.tar.gz -C /usr ...

  10. Codeforce 270A - Fancy Fence (正多边形)

    Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fe ...