assert执行php,PHP:如何使用assert

按合同设计

我相信断言在PHP中用得不多.你可以使用它,如果你Design By Contract.

Design by Contract (DbC) or

Programming by Contract is an approach

to designing computer software. It

prescribes that software designers

should define formal, precise and

verifiable interface specifications

for software components, which extend

the ordinary definition of abstract

data types with preconditions,

postconditions and invariants. These

specifications are referred to as

“contracts”, in accordance with a

conceptual metaphor with the

conditions and obligations of business

contracts.

这个tutorial解释了一下.

TDD /单元测试

我建议你按照这些3 simple rules(必读文章)对你的代码(TDD)进行单元测试.

You are not allowed to write any production code unless it is to make a

failing unit test pass.

You are not allowed to write any more of a unit test than is sufficient

to fail; and compilation failures are

failures.

You are not allowed to write any more production code than is

sufficient to pass the one failing

unit test.

You must begin by writing a unit test

for the functionality that you intend

to write. But by rule 2, you can’t

write very much of that unit test. As

soon as the unit test code fails to

compile, or fails an assertion, you

must stop and write production code.

But by rule 3 you can only write the

production code that makes the test

compile or pass, and no more.

If you think about this you will

realize that you simply cannot write

very much code at all without

compiling and executing something.

Indeed, this is really the point.

要练习(训练),你应该使用优秀的PHPUnit框架.你应该阅读这篇Writing Tests for PHPUnit以了解这门学科.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值