0

PhpUnit 有一个基于现有类的 skel 生成器。

但它的作品一次。

如果稍后添加了一些新方法(因为 dev 不适用于 tdd ),则测试文件不完整。

是否有工具可以为未覆盖的方法生成骨架?

4

2 回答 2

0

I don't know any, and I also don't see the need. That skeleton generator generates one test method per function it finds, but you cannot test all use cases of a slightly advanced function within only one test function.

Also, the name of the test function is generated - but better names can and should be created to describe the intended test case or behavior of the tested function. Like "testGetQuoteFromStockMarket" vs. "testGettingMicrosoftQuoteFromStockMarketShouldReturnQuoteObject" and "testGettingUmbrellaCorporationFromStockMarketShouldFailWithException".

Note that you cannot test the throwing of exceptions in combination with cases that do not throw exceptions.

So all in all there simply is no use case to create "one test method per method" at all, and if you add new methods, it is your task to manually add the appropriate number of new tests for that - the generated code coverage statistics will tell you how well you did, or which functions are untested.

于 2014-01-26T23:11:04.880 回答
0

AFAIK 没有内置的 phpunit 功能来更新自动生成的测试代码;这是大多数代码生成器的典型特征。

好消息是,每个功能都添加得非常干净和独立。所以我要做的是将现有的单元测试文件重命名为 *.old,重新生成一个新的测试文件,然后使用meld(或您选择的可视差异工具)合并新功能。

顺便说一句:无论如何,实际上只在新课程开始时才需要自动测试生成;每个函数只有一个单元测试的想法更多是为了生成好的覆盖率统计数据来取悦你的老板;从构建好的软件的角度来看,某些功能需要多次测试,而某些功能(想到 getter 和 setter)实际上不需要任何测试,有时单个单元测试最好覆盖多个功能(getter 和 setter再次浮现在脑海)。

于 2014-01-27T01:04:39.697 回答