gpt4 book ai didi

php - 测试不存在的代码

转载 作者:行者123 更新时间:2023-11-28 21:04:16 24 4
gpt4 key购买 nike

<分区>

TDD 声称我应该先编写测试。假设我想编写一个服务,如果我还没有任何东西,我该如何开始为该服务编写测试呢?第一个测试是什么?尝试实例化服务并获得异常?

基于 PHP Laravel 的示例:

class ServiceTest extends TestCase
{
public function testServiceExists()
{
$service = App::make('grid');
}
}

结果:

PHPUnit 5.5.4 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 123 ms, Memory: 14.00MB

There was 1 error:

1) ServiceTest::testServiceExists ReflectionException: Class grid does not exist

/home/supertrall/domains/md.local/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:749 /home/supertrall/domains/md.local/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:644 /home/supertrall/domains/md.local/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:709 /home/supertrall/domains/md.local/laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237 /home/supertrall/domains/md.local/laravel/tests/Grid/ServiceTest.php:20

ERRORS! Tests: 1, Assertions: 0, Errors: 1.

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com