I didn't quite understand why this was made. We create our local test environments using docker-compose, and so I read: > Creating reliable and fully-initialized service dependencies using raw Docker commands or using Docker Compose requires good knowledge of Docker internals and how to best run specific technologies in a container This sounds like a abstraction over docker-compose, which lets you define your docker…
Testcontainers
11–20 of 260 posts
Re: Testcontainers
#12Earlier quoted context omitted.
Testcontainers are for testing individual components, apart from the application. I built a new service registry recently, its unit tests spins up a zookeeper instance for the duration of the test, and then kills it. Also very nice with databases. Spin up a clean db, run migrations, then test db code with zero worries about accidentally leaving stuff in a table that poisons other tests. I guess the killer feature is…
> Also very nice with databases. Spin up a clean db, run migrations, then test db code with zero worries about accidentally leaving stuff in a table that poisons other tests. Are you spinning up a new instance between every test case? Because that sounds painfully slow. I would just define a function which DELETEs all the data and call it between every test.
Can only speak for the Golang version of the lib, but spinning up new instances was surprisingly quick.
Re: Testcontainers
#13Pulling up infra to run unit tests is an anti-pattern. This is a great tool for integration tests, though.
Re: Testcontainers
#14Re: Testcontainers
#15Re: Testcontainers
#16Re: Testcontainers
#17Pretty much every project I create now has testcontainers for integration testing :)
I setup CI so it lints, builds, unit tests then integration tests (using testcontainers)
https://github.com/turbolytics/latte/blob/main/.github/workf...
Their language bindings provide nice helper functions for common database operations (like generating a connection uri from a container user)
https://github.com/turbolytics/latte/blob/main/internal/sour...
I use them in $day job use them in side projects use them everywhere :)
Re: Testcontainers
#18Earlier quoted context omitted.
What if you are unit testing something that is dependent on infra?
Typically you mock them in unit tests.
Re: Testcontainers
#19Re: Testcontainers
#20Unit test suppose to be fast. Especially during coding. I wonder how this is necessary & not affecting the test feedback speed