REST API Testing best strategy

I’m currently developing a personal project using Django REST + React and as it grows more complex, I want to add unit testing to ensure that changes don’t affect previous functionality. However, I’m not sure exactly what to test for. Should I simply test the responses from the API endpoints, should I try random input to check if it’s validated properly, should I try getting access or changing data that belong to a different user? What is the best strategy to ensure that a REST API is both stable and secure through testing?

Go to Source
Author: Antonis Karvelas

Testable architecture of micro-services

Into:

There are mutliple ways to test code: unit tests /e2e / manual testing /..

I’m developing a project that it’s implementation details changes very quickly (and sometimes the core functions as well).

Some of our microservers talk to each other directly while some others communicate using events like kafka.

Problem:

When I create an e2e test (for the backend image only), before each test(s), I build the docker image of my micro service and run it again on (each) test.

I find it really hard to set up this kind of e2e test for a micro service that directly talks to other microservices (sending get/post/.. requests).

As a result, I also build/pull the other images and run them before each tests as well. But it’s not that easy because you can end up implementing a version of docker-compose in you tests infrastructure.

I would like to minimize the amount of errors that can come from other services and test a specific microservice.

Possible solution:

Changing the microservices architecture.

When ever it is possible, a micro service will communicate with others using events. So in the tests, we only need to setup a kafka and the microservice that we try to test.

I only though of this solution from testing perspective and not from “what is best”, for example, it’s faster to communicate without kafka.

Question:

What are the pros and cons of my proposal? From your experience, is it maintainable?

Go to Source
Author: Stav Alfi

Clean Architecture use case testing

Use case interactors in the Clean Architecture consists of the application specific business rules.

Clean Architecture diagram

Interactors uses the Data Access Interface to fetch the required data from the data access layer.
Basically I see two approaches to test these interactors.

  • Using test doubles rather than the actual data access layer
  • Using the real data access layer (e.g. sql database, webservice)

I personally prefer the first approach and test the data access layer seperately.
The interactor tests uses the Data Access Interface with the test doubles and the entities in the inner circle.
An architectural boundary is crossed in both approaches.

Is the first test approach considered as Integration Testing with a narrower scope or is it just Unit Testing?

Go to Source
Author: Stefan

Is the self-shunt pattern the same as stubbing in TDD?

I am reading the book TDD by Example and one of the patterns demonstrated was the self-shunt pattern.

Basically, if I am not mistaken, if I have a test like this:

test("list of users should receive a new user"), () => {
  const user = new User()
  const listOfUsers = new ListOfUsers()
  listOfUsers.insert(user)
}

Then, the only way to know if listOfUsers actually received the user, is to stub it, correct?

class ListOfUsersStub {
  constructor () {
    this.users = []
  }

  insert (user) {
    this.users.push(user)
    return this.users
  }
}

then I can test it so:

test("list of users should receive a new user"), () => {
  const user = new User()
  const listOfUsers = new ListOfUsers()
  const result = listOfUsers.insert(user)
  expect(result.users).toContain(user)
}

Is this the same as the self shunt pattern? Or am I missing something?

Thanks

Go to Source
Author: kibe