jeudi 24 novembre 2016

Test the code that doesn't exist

TDD claims that I should write tests first. Say I want to write a service, how do I start writing tests for the service if I don't have anything yet at all? What would be the first test? An attempt to instantiate the service and get an exception?

PHP Laravel-based example:

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

Result:

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.

Aucun commentaire:

Enregistrer un commentaire