E2E testing
E2E testing focuses on the system as a whole and is more focused on use cases and scenarios than on specific functions or subsystems working together. For example, if you have an API, you can test the API like a black box, sending requests that make sense for specific use cases, such as registration and first login, or creating, updating, listing, and deleting a shopping list.
The most common case for E2E testing is using a web browser to consume a web application that sends requests to the server. In those scenarios, you use tools such as Selenium, Playwright, Cypress, or similar tools to simulate user interactions. However, you can use a simple HTTP client to send requests and analyze the responses for APIs. Let’s see how we can do that:
func TestRegisterAndLogin(t *testing.T) {
resp1, err := http.Post("http://localhost:8080/register",
"application/json", strings.NewReader(`{"username": "user",
"...