{
    "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest",
    "locale": "en",
    "title": "Testing your app with Pest · DeLaParra Services",
    "description": "Installing Pest in Laravel, the difference between unit and feature tests, writing your first test, and getting your AI assistant to write tests for you first.",
    "alternates": {
        "en": "https://delaparra-services.nl/manuals/je-app-testen-met-pest",
        "nl": "https://delaparra-services.nl/nl/handleidingen/je-app-testen-met-pest"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.csv",
        "md": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.md",
        "json": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.json",
        "zip": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.zip",
        "pdf": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.csv",
            "encodingFormat": "text/csv",
            "name": "je-app-testen-met-pest.csv"
        },
        {
            "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.json",
            "encodingFormat": "application/json",
            "name": "je-app-testen-met-pest.json"
        },
        {
            "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.md",
            "encodingFormat": "text/markdown",
            "name": "je-app-testen-met-pest.md"
        },
        {
            "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.pdf",
            "encodingFormat": "application/pdf",
            "name": "je-app-testen-met-pest.pdf"
        },
        {
            "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.zip",
            "encodingFormat": "application/zip",
            "name": "je-app-testen-met-pest.zip"
        }
    ],
    "markdown": "# Testing your app with Pest\n\nA **test** is a piece of code that checks whether your other code is doing what it’s supposed to. If your AI assistant changes something, the tests will show within a few seconds whether anything else has gone wrong.\n\n**Pest** is a PHP testing tool with a simple syntax. New Laravel projects can have Pest included as part of the installation.\n\n## Step 1: Install (if you don’t already have it)\n\n```bash\ncomposer require pestphp/pest --dev --with-all-dependencies\n./vendor/bin/pest --init\n```\n\nRunning tests:\n\n```bash\nphp artisan test\n# of\n./vendor/bin/pest\n```\n\n## Step 2: the difference between types of tests\n\n| Type | Test | Speed | Folder |\n|---|---|---|---|\n| **Unit test** | A single function or class, independent of the rest | Very fast | `tests/Unit` |\n| **Feature test** | A complete sequence: request → controller → database → response | Fast | `tests/Feature` |\n| **End-to-end (E2E)** | The app in a real browser | Slow | using, for example, Playwright or Pest browser tests |\n\nStart with feature tests: they catch most of the issues in a standard web app.\n\n## Step 3: your first test\n\n```bash\nphp artisan make:test FactuurTest --pest\n```\n\n```php\nuse App\\Models\\User;\nuse App\\Models\\Klant;\n\nit('maakt een factuur aan', function () {\n    $user = User::factory()->create();\n    $klant = Klant::factory()->create();\n\n    $this->actingAs($user)\n        ->post('/facturen', ['klant_id' => $klant->id, 'bedrag' => 121.00])\n        ->assertRedirect();\n\n    expect($klant->facturen()->count())->toBe(1);\n});\n\nit('weigert een negatief bedrag', function () {\n    $user = User::factory()->create();\n\n    $this->actingAs($user)\n        ->post('/facturen', ['klant_id' => 1, 'bedrag' => -5])\n        ->assertSessionHasErrors('bedrag');\n});\n```\n\nIn `phpunit.xml`, set up a separate test database (for example, an in-memory SQLite database) so that tests never affect your real data. Use `RefreshDatabase` to ensure that each test starts with an empty database.\n\n## Step 4: Let your AI assistant write the test first\n\nThis is called **test-driven development (TDD)**:\n\n1. Write (or have someone write) a test that describes what you want. It should fail at first (red).\n2. Let the assistant write the code until the test passes (green).\n3. Tidy up the code without causing the test to fail (refactor).\n\nPut it this way:\n\n> First, write a PEST test: a customer without an email address should not receive a reminder. Show that it fails. Only then should you amend the code.\n\nThe skills **test-driven-development** and **tdd-laravel** ensure your assistant does this consistently. With **verification-before-completion**, it only reports ‘done’ once the tests have actually passed.\n\n## Step 5: Running tests automatically\n\nRun your tests with every push using GitHub Actions. You’ll then see a green tick or a red cross for every pull request. See *Putting your Laravel app online*.\n\n## A few terms\n\n- **Assertion:** the check in a test (`assertStatus(200)`, `expect(...)->toBe(...)`).\n- **Factory:** generates test data (`User::factory()`).\n- **Mock / stub:** a fake version of an external service, such as a payment provider, so that your test does not actually make a payment.\n- **Regression:** something that used to work but is now broken. Tests are your safety net.\n\n## Need help?\n\nWould you like someone to check whether your tests cover the important aspects? Take a look at **AI code review**.\n\n## Skills\n\n- [Test-Driven Development (TDD)] (/nl/skills/test-driven-development)\n- [Test-Driven Development] (/nl/skills/tdd-laravel)\n- [Laravel 13 Testing — Pest PHP 4 & PHPUnit 12] (/nl/skills/laravel-testing)\n- [E2E Testing Patterns] (/nl/skills/e2e-testing-patterns)\n- [Web Application Testing] (/nl/skills/webapp-testing)\n- [Verification Before Completion] (/nl/skills/verification-before-completion)\n\n## Related services\n\n- [Beoordeling van AI-code] (/nl/services#service-05)\n- [Maatwerk software en webapplicaties] (/nl/services#service-03)\n\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "TechArticle",
                "@id": "https://delaparra-services.nl/manuals/je-app-testen-met-pest#article",
                "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest",
                "headline": "Testing your app with Pest",
                "description": "Installing Pest in Laravel, the difference between unit and feature tests, writing your first test, and getting your AI assistant to write tests for you first.",
                "inLanguage": "en",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/manuals/je-app-testen-met-pest#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/manuals/je-app-testen-met-pest#dataset",
                "name": "Testing your app with Pest",
                "description": "Installing Pest in Laravel, the difference between unit and feature tests, writing your first test, and getting your AI assistant to write tests for you first.",
                "url": "https://delaparra-services.nl/manuals/je-app-testen-met-pest",
                "identifier": "https://delaparra-services.nl/manuals/je-app-testen-met-pest#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/manuals/je-app-testen-met-pest#article"
                },
                "publisher": {
                    "@type": "Organization",
                    "name": "DeLaParra Services",
                    "url": "https://delaparra-services.nl/"
                },
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/manuals#dataset",
                    "name": "Manuals for working on your own app",
                    "url": "https://delaparra-services.nl/manuals"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "je-app-testen-met-pest.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.csv",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "je-app-testen-met-pest.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.json",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "je-app-testen-met-pest.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.md",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "je-app-testen-met-pest.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.pdf",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "je-app-testen-met-pest.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/manuals/je-app-testen-met-pest.zip",
                        "inLanguage": "en"
                    }
                ]
            }
        ]
    }
}