Java alternative for Ruby's vcr?

4k Views Asked by At

Is there a java alternative for Ruby's VCR?

As far as I understand, the benefits of using VCR are immense, you can run an "integration test" and record the results, store them some where locally. Now from the next time when you need to run your tests, you can mockup your actual database hits with the data recorded from the first run.

  1. Is there something similar in java world?
  2. If not, what kind of bottlenecks I might face if I try to implement it?

VCR only records HTTP interactions, but can such an approach be done to record, say any kind of database operations/function calls to other team's APIs which I don't need to test, basically this will relieve me from mocking up so many things by automating it.

Here is an example of VCR with Ruby's unit tests:

4

There are 4 best solutions below

3
On BEST ANSWER

Check out betamax. It's a groovy port of VCR. It should work on the JVM with any language, I believe.

As for using a VCR-like library to record/playback DB interactions: Sven Fuchs tried this approach and didn't see much benefit to it.

3
On

Another implementation of this record-playback-concept is easyVCR, it is an MIT-licensed project backed by a company.

engineering-blog: https://www.easypost.com/blog/2022-10-04-vcr-the-must-have-companion-for-api-testing

github: https://github.com/EasyPost/easyvcr-java

2
On

betamax has been abandoned. You may want to check out mocktail which is a java-method level record and play mechanism. That means - record and play is applicable on almost anything, not just on HTTP.

Disclaimer: I created Mocktail

0
On

Check out anystub. this is java-lib. it allows to record/playback any String get(String... keys) invocations instead of only HTTP trafic.