PnxAssert

作为一个通用型测试框架,最基本的断言必不可少;PnxAssert采用fluent API,提供常用对象的断言能力。参考如下使用示范:

//基本数据类型
boolean bActual = false;
PnxAssert.assertThat(bActual).isFalse();

int actual = 100;
PnxAssert.assertThat(actual).isEqualTo(100);
PnxAssert.assertThat(actual).isGreaterThan(0);
PnxAssert.assertThat(actual).isGreaterThan(0).isEqualTo(100);

//字符串
 String actual = "PnxTest is awesome!";

PnxAssert.assertThat(actual).isEqualTo("PnxTest is awesome!");
PnxAssert.assertThat(actual).isEqualToIgnoringCase("PnxTest is awesome!");
PnxAssert.assertThat(actual).isNotNull();
PnxAssert.assertThat(actual).startsWith("Pnx").endsWith("awesome!");
PnxAssert.assertThat(actual).hasLength(19);
PnxAssert.assertThat(actual).contains("awesome");

PnxAssert.assertThat(actual).isNotNull()
  .startsWith("Pnx")
  .endsWith("awesome!")
  .hasLength(19);

//数组
int[] actual = new int[]{10,20,30};
PnxAssert.assertThat(actual)
  .isNotEmpty()
  .hasSize(3)
  .hasItem(10);

String[] actual = new String[]{"PnxTest", "Awesome"};
PnxAssert.assertThat(actual)
  .isNotEmpty()
  .hasSize(2)
  .hasItem("PnxTest")
  .contains("PnxTest", "AweSome");

//集合
List<String> actual = new ArrayList<>();
actual.add("aa");
actual.add("bb");
actual.add("cc");

PnxAssert.assertThat(actual)
  .isNotEmpty()
  .hasSize(3)
  .consistsOf("cc", "aa", "bb")
  .consistsOfOrdered("aa", "bb", "cc")
  .contains("aa", "bb")
  .doesNotContain("dd");

使用as功能增加描述:

PnxAssert.assertThat(amount)
                .as("输入的金额必须多于5元")
                .isGreaterThanOrEqualTo(5);

注意:as必须紧跟在assertThat后面,否则无法获取到描述