13

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:

Myron Marston
  • 21,452
  • 5
  • 64
  • 63
zengr
  • 38,346
  • 37
  • 130
  • 192

3 Answers3

10

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.

vault
  • 3,930
  • 1
  • 35
  • 46
Myron Marston
  • 21,452
  • 5
  • 64
  • 63
  • Thanks the reply, in case of Sven Fuchs, the database init time might be very low since he was using a regular rails project. But in my case, if I try to get around the database (in java) I will get a gain of 10mins of init time! I think I will try to write a java port sometime and see how it works for me. HTTP interaction recording is not my concern unfortunately. – zengr Oct 16 '11 at 19:19
  • betamax link is dead, updated link to github --> https://github.com/betamaxteam/betamax – Mike R Jul 07 '16 at 21:53
  • 2
    betamax is no longer maintained. I wouldn't recommend relying on a library that is unmaintained – cohen990 Apr 30 '18 at 13:11
1

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

feech
  • 404
  • 4
  • 15
0

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.