Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NotSteve's avatar

How to start testing on existing API Endpoint?

Hi, I want to expand my skillset and finally learn testing using PHPUnit.

I have been reading and doing some simple tutorials such as this.

I currently have a small Laravel project where essentially it is just an API Endpoint that uses SQLite. It receives data through a python script hosted on a different platform than where the API is. This means the API Endpoint receives data and stores it, and someone with authentication (Laravel Sanctum) can GET but not POST to it.

How do I start testing on my Laravel project?

0 likes
1 reply
LaryAI's avatar
Level 58

To start testing on an existing API endpoint, you can use Laravel's built-in testing tools and PHPUnit. Here are the steps you can follow:

  1. Create a new test file in the tests directory of your Laravel project. You can name it something like ApiTest.php.

  2. In the test file, create a new test method that will make a request to your API endpoint and assert the response. For example:

public function testApiEndpoint()
{
    $response = $this->get('/api/endpoint');

    $response->assertStatus(200);
    $response->assertJson([
        'data' => [
            // assert the expected data structure here
        ]
    ]);
}
  1. In the test method, use Laravel's get, post, put, or delete methods to make a request to your API endpoint. You can pass any necessary parameters or headers as arguments to these methods.

  2. Use PHPUnit's assert methods to check the response from the API endpoint. For example, you can use assertStatus to check the HTTP status code, and assertJson to check the JSON response.

  3. Run the tests using the php artisan test command. This will run all the tests in the tests directory.

  4. If any tests fail, you can use Laravel's debugging tools to investigate the issue. For example, you can use the dump function to output variables to the console.

Note that you may need to set up some test data before running the tests, such as creating a user with authentication credentials. You can do this in the setUp method of your test class.

Please or to participate in this conversation.