viernes, mayo 12, 2017

Testing Spring Data + Spring Boot applications with Arquillian (Part 2)


In previous post, I wrote about how to test Spring Data application using Docker with Arquillian Cube. The test looked like:


This test just starts Redis container, then populate data using restTemplate and post method, then execute the logic under test (testing GET HTTP method) and finally stop the Redis container.

It is good, it works but there are several problems there:
  • The first one is that we are using REST API to prepare data set of the test. The problem here is that the test might fail not because a failure on code under test but because of the preparation of the test (insertion of data).
  • The second one is that if POST endpoint changes format/location, then you need to remember to change everywhere in the tests where it is used.
  • The last one is that each test should leave the environment as found before execution, so the test is isolated from all executions. The problem is that to do it in this approach you need to delete the previous elements inserted by POST. This means to add DELETE HTTP method which might not be always implemented in endpoint, or it might be restricted to some concrete users so need to deal with special authentication things.
To avoid this problem Arquillian Persistence Extension (aka APE) was created. This extensions integrates with DBUnit and Flyway for SQL databases, NoSQLUnit for No SQL databases and Postman collections for REST services so you can populate your backend before testing the real test use case and clean the persistence storage after the test is executed.

Also population data is stored inside a file, so this means that can be reused in all tests and easily changed in case of any schema update.

Let's see example of Part 1 of the post but updating to use APE.

And the file (pings.json) used for populating Redis instance with data looks like:


Notice that in this test you have replaced the POST calls for something that directly inserts into the storage. In this way you avoid any failure that might occurs in the insertion logic (which is not the part under test). Finally after each test method, Redis instance is cleaned so other tests finds Redis clean and into known state. 

Project can be found at https://github.com/arquillian-testing-microservices/pingpongbootredis

We keep learning,
Alex
Y es que no puedo estar así, Las manecillas del reloj, Son el demonio que me tiene hablando solo (Tocado y Hundido - Melendi)
Music: https://www.youtube.com/watch?v=1JwAr4ZxdMk



5 comentarios:

Unknown dijo...

Hello,

I'm triying to use ContainerDslRule in a test with cassandra and Spring:

@RunWith(SpringRunner.class)

public static ContainerDslRule cassandra = new ContainerDslRule("cassandra:3.0", "cassandra_test")
.withPortBinding(9042, 7000, 7199);

My problem is that cassandra has a long startup period, and I would like to reuse conteiners during coding phase.

I'm trying to configure ContainerDslRule with a different connectionMode (STARTORCONNECT), but after several tries, I dont know if it's possible

Is there any way to configure ContainerDslRule with this capability?

Thanks

PalaPala dijo...

Pandora Outlet
Jordans 11
Air Jordan 4
Air Jordan 9
Red Bottom Shoes For Women
Jordan Retro 11
Pandora Jewelry Official Site
Yeezy boost 350 v2
Nike Air Max 270
Latrice20190108

Hualala dijo...

Kyrie Irving Shoes
Air Jordan 11
Air Jordan 9
Jordans 11
Yeezy boost 350 v2
Jordan 4 Retro
Jordan 11
Pandora Jewelry Outlet
Air Max 270
Paul20190321

Ada Smith dijo...

Online casino is a new generation of games for good people. successful mobile slots casino Knowing what an online casino is, you are already better than others.

mclesle dijo...

naviguer autour de ce site Web www.dolabuy.ru vous pouvez les essayer YSL Dolabuy cet article sacs réplique gucci