Package com.redis.vl.test.vcr
Class VCRExtension
java.lang.Object
com.redis.vl.test.vcr.VCRExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.TestWatcher
public class VCRExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.TestWatcher
JUnit 5 extension that provides VCR (Video Cassette Recorder) functionality for recording and
playing back LLM API calls during tests.
This extension manages:
- Redis container lifecycle with AOF/RDB persistence
- Cassette storage and retrieval
- Test context and call counter management
- Automatic wrapping of
@VCRModelannotated fields
Usage with declarative field wrapping:
@VCRTest(mode = VCRMode.PLAYBACK_OR_RECORD)
class MyLLMTest {
@VCRModel
private EmbeddingModel embeddingModel;
@VCRModel
private ChatModel chatModel;
@BeforeEach
void setup() {
// Initialize models normally - VCR wraps them automatically
embeddingModel = new OpenAiEmbeddingModel(...);
chatModel = new OpenAiChatModel(...);
}
@Test
void testLLMCall() {
// LLM calls are automatically recorded/replayed
embeddingModel.embed("Hello");
chatModel.generate("What is Redis?");
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidafterEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidtestFailed(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Throwable cause) voidtestSuccessful(org.junit.jupiter.api.extension.ExtensionContext extensionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestWatcher
testAborted, testDisabled
-
Constructor Details
-
VCRExtension
public VCRExtension()
-
-
Method Details
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
Exception
-
testSuccessful
public void testSuccessful(org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
testSuccessfulin interfaceorg.junit.jupiter.api.extension.TestWatcher
-
testFailed
public void testFailed(org.junit.jupiter.api.extension.ExtensionContext extensionContext, Throwable cause) - Specified by:
testFailedin interfaceorg.junit.jupiter.api.extension.TestWatcher
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback- Throws:
Exception
-