json-snapshot.github.io
json-snapshot.github.io copied to clipboard
Support parameterised tests
Hi,
When using JUnit's Parameterized test runner, snapshot testing can not be used, as only one snapshot per test method is permitted due to the way that the snapshot is resolved on subsequent runs.
I've tried a small change to support passing qualifiers through to the matcher:
private String someParameter;
public ATestClass(String someParameter) throws IOException {
this.someParameter = someParameter;
}
@Test
public void test() throws Exception {
Object actual = ...
expect(actual).toMatchSnapshot(someParameter);
}
and
public void toMatchSnapshot(Object... qualifiers) {
This seems to work pretty well. The .snap
ends up as you would expect:
ATestClass.test(theValueOfSomeParameter)=[
I'm happy to raise a PR if this would be of interest.
Thanks, -Dan