eph baum dot dev

← Back to blog

Types of Tests in Laravel

Published on 03/26/2023 10:31 AM by Eph Baum

Featured Image

Laravel is a popular PHP web application framework, and testing is an essential part of its development process. Laravel provides a suite of tools for creating and executing tests, making it easier to ensure your application works as expected. Here’s a breakdown of the different types of tests you might encounter in Laravel:

  1. Unit Tests: Unit tests are designed to test small, isolated pieces of code, such as individual functions or methods within a class. They focus on testing the application’s business logic and ensure that each component works correctly in isolation. In Laravel, you can create unit tests by extending the PHPUnit\Framework\TestCase class. Unit tests should be simple, quick to execute, and have minimal dependencies on external resources.
  2. Feature Tests: Feature tests, also known as functional tests, focus on testing the behavior of your application from the user’s perspective. They test the interaction between different components of the application, such as controllers, middleware, and views. Feature tests often simulate user input and verify that the application responds as expected, ensuring that the different components work together correctly. In Laravel, you can create feature tests by extending the Tests\TestCase class. Feature tests may require more setup and configuration than unit tests, such as setting up the application environment, seeding the database, or mocking external services.
  3. Integration Tests: Integration tests evaluate how different parts of the application work together by testing the communication and data flow between components, such as database interactions, APIs, or third-party services. Integration tests help ensure that the application’s components work correctly when integrated, and they can help identify issues with data formats, network communication, or third-party service compatibility. In Laravel, you can write integration tests similarly to feature tests, but the focus is more on the interaction with external systems.

Other common types of tests in Laravel include:

  1. Browser Tests (Dusk): Laravel Dusk is a browser testing tool that allows you to test your application’s user interface and JavaScript-driven behavior. Dusk tests are similar to feature tests, but they interact with the application using a real web browser, providing more accurate end-to-end testing. Dusk tests can help ensure that your front-end components and JavaScript code work correctly with your back-end application.
  2. End-to-End Tests (E2E): End-to-end tests verify that the entire application works as expected, from the user interface down to the data storage and retrieval. These tests simulate real user scenarios, including interactions with the application, and can help identify issues that might not be caught by unit, feature, or integration tests. E2E tests are typically more complex and time-consuming than other tests, so they’re often run less frequently or in a separate testing environment.

In summary, different types of tests serve different purposes in Laravel and PHP web application testing. Unit tests focus on individual code components, feature tests focus on user interactions and application behavior, and integration tests focus on communication between application components and external systems. Additionally, browser tests and end-to-end tests provide more comprehensive testing for user interface and overall application functionality.

Written by Eph Baum

  • Making Brutalist Design Accessible: A Journey in WCAG AA Compliance

    Making Brutalist Design Accessible: A Journey in WCAG AA Compliance

    How I transformed my brutalist blog theme to meet WCAG AA accessibility standards while preserving its vibrant, random aesthetic. Talking about contrast ratios, color theory, and inclusive design.

  • Building Horror Movie Season: A Journey in AI-Augmented Development

    Building Horror Movie Season: A Journey in AI-Augmented Development

    How I built a production web app primarily through 'vibe coding' with Claude, and what it taught me about the future of software development. A deep dive into AI-augmented development, the Horror Movie Season app, and reflections on the evolving role of engineers in the age of LLMs.

  • Chaos Engineering: Building Resiliency in Ourselves and Our Systems

    Chaos Engineering: Building Resiliency in Ourselves and Our Systems

    Chaos Engineering isn't just about breaking systems — it's about building resilient teams, processes, and cultures. Learn how deliberate practice strengthens both technical and human architecture, and discover "Eph's Law": If a single engineer can bring down production, the failure isn't theirs — it's the process.

  • Using LLMs to Audit and Clean Up Your Codebase: A Real-World Example

    Using LLMs to Audit and Clean Up Your Codebase: A Real-World Example

    How I used an LLM to systematically audit and remove 228 unused image files from my legacy dev blog repository, saving hours of manual work and demonstrating the practical value of AI-assisted development.

  • Migrating from Ghost CMS to Astro: A Complete Journey

    Migrating from Ghost CMS to Astro: A Complete Journey

    The complete 2-year journey of migrating from Ghost CMS to Astro—from initial script development in October 2023 to final completion in October 2025. Documents the blog's 11-year evolution, custom backup conversion script, image restoration process, and the intensive 4-day development sprint. Includes honest insights about how a few days of actual work got spread across two years due to life priorities.

  • 50 Stars - Puzzle Solver (of Little Renown)

    50 Stars - Puzzle Solver (of Little Renown)

    From coding puzzle dropout to 50-star champion—discover how AI became the ultimate coding partner for completing Advent of Code 2023. A celebration of persistence, imposter syndrome, and the surprising ways generative AI can help you level up your problem-solving game.