承接 nwehr/hhunit 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nwehr/hhunit

Composer 安装命令:

composer require --dev nwehr/hhunit

包简介

Unit testing for HHVM

README 文档

README

A unit test framework specifically for the Hack language.

Test Suites

To create a test suite, write a class with the <<TestSuite>> attribute. Individual tests use the <<Test>> attribute. You can skip an entire test suite or indivitual tests using the <<Skip>> attribute.

<?hh
use hhUnit\Assert;

<<TestSuite>>
class MyTestSuite {

    <<Test>>
    public function someTest(Assert $assert) : void {
        $assert->int(1)->equalTo(1);
    }

    <<Test, Skip>>
    public function skippedTest(Assert $assert) : void {
        $assert->bool(true)->not()->equalTo(false);
    }
}

Assertions

All of the scalar types are available in the Assert class.

  • bool
  • int
  • float
  • string
  • array

Any assertion may be negated by calling not() before the final assertion method.

$assert->bool(true)->not()->equalTo(false);

Bool Assertions

$assert->bool(true)->equalTo(true);

Int Assertions

$assert->int(1)->equalTo(1);

$assert->int(1)->greaterThan(0);
$assert->int(1)->greaterThanOrEqualTo(0);

$assert->int(0)->lessThan(1);
$assert->int(0)->lessThanOrEqualTo(1);

Float Assertions

$assert->float(1.1)->equalTo(1.1);

$assert->float(1.2)->greaterThan(1.1);
$assert->float(1.2)->greaterThanOrEqualTo(1.2);

$assert->float(1.1)->lessThan(1.2);
$assert->float(1.1)->lessThanOrEqualTo(1.2);

String Assertions

$assert->string("abc")->equalTo("abc");
$assert->string("abc")->hasLength(3);
$assert->string("gtolemans@gmail.com")->contains("gmail");
$assert->string("gtolemans@gmail.com")->matchesPattern("/^\S+@\S+\.\S+$/");

Array Assertions

$assert->array([1,2,3])->equalTo([1,2,3]);
$assert->array([1,2,3])->contains(1);

Map Assertions

$assert->map<string, string>(Map{"key1" => "value1"})->equalTo(Map{"key1" => "value1"});
$assert->map<string, string>(Map{"key1" => "value1"})->containsKey("key1");

Vector Assertions

$assert->vector<string>(Vector{"value1"})->equalTo(Vector{"value1});
$assert->vector<string>(Vector{"value1"})->containsValue("value1");

Install

$ composer require nwehr/hhunit

Run Tests

./vendor/bin/hhUnit

Tester Output

Test Suites        : 5
Tests              : 18
Assertions         : 20
Assertion Failures : 0

Ignore

To prevent hhUnit from including individual source files or entire directories add a .hhunitignore file in your tests directory.

.hhunitignore

./IgnoredTestSuite.hh
../ignored_dir

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Hack

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2020-07-14