json-snapshot.github.io icon indicating copy to clipboard operation
json-snapshot.github.io copied to clipboard

Support parameterised tests

Open dspasojevic opened this issue 5 years ago • 1 comments

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

dspasojevic avatar Apr 09 '19 11:04 dspasojevic