Pixelairport's avatar

New to testing: 2 questions

I started with testing my application and have two questions. I have a main service (gateway), which uses multiple microservice. I already finished tests for all microservices. But now it all comes together, when the gateway redirects everything to the right microservice.

  1. I have the problem, that the RefreshDatabase trait could not work, because everything which is created, updated or deleted by the user, will be done in the microservices. So my question is, if there is a trick, or if i only need to extend my tests and maybe do the full test with create and delete at the end, to have a clean database at the next test. What I learned about laravel is, that there is a trait or workaround most of the time. That is why Im asking.

  2. Do you test only local or also do tests live on the server? I mean do you have live test servers maybe also with microservices?

0 likes
5 replies
amirkamizi's avatar
Level 3

with the first question, I had the same thing. there are multiple things you can do:

a: create and delete as you said

b: what kind of information those microservices create? you create them yourself rather than sending them to microservices. then the refreshdatabase would work (Only do this if you are sure that the other tests cover the microservice itself, and it sends and receives data correctly)

c: in php unit you can create a test database. in the testing tutorials on laracast you can see how it works.

with the second question, in depends on you and your project. in my opinion it's always a good idea to test it on a testing server at least. if you can test it on the live server then even better. it's just my opinion.

1 like
Pixelairport's avatar

thx @amirkamizi . a sounds ok, b sounds not so good. I dont know if i understand c right. I just watched https://laracasts.com/series/phpunit-testing-in-laravel/episodes/5. They say something about test-database. But i already use memory database instead of live db. But how can i also say my microservices that this is a test. Would it be a good idea to send a variable in header where i say testing=true and if it is true my microservice provider change the database on the fly to a testing db?

amirkamizi's avatar

that is possible. OR you could create a test live server for your microservices as well. if the microservice is working properly and has passed all its own tests, then I would deploy it on a test server as well.

that way even if another developer or program wanted to use that microservice they can also use the test server.

for example for many websites that offer b2b services, they have 2 APIs. one is for test-example.com/api and the other is for example.com/api

that way you as another developer or another business who wants to work with them, can develop your API and program and make as many tests as you want. if it's a shop you can shop and many weeks later search for your purchase with that code and still would work.

I personally like this type rather than cleaning the database in case it's testing, for 2 reasons:

1- my personal taste (you could do whatever you prefer)

2- we are humans and we make mistakes. imagine if you want to send a test but you don't add it in your header and the microservice doesn't know it's a test so it would add data to the live database.

I hope I could explain properly.

1 like
Pixelairport's avatar

thx @amirkamizi again... that sounds good. I will do some tests with test databases for microservices tomorrow. But that sound like a very good idea. thank you.

1 like

Please or to participate in this conversation.