ApprovalTests.Java icon indicating copy to clipboard operation
ApprovalTests.Java copied to clipboard

Support for jqwik

Open pfichtner opened this issue 4 years ago • 14 comments

With #133 I suggested approvals to be working with jqwik but it doesn't (approvals version 12.1.1). Only after adding jqwik's Property class to AttributeStackSelector's classNames my example test worked. Did I miss something?

pfichtner avatar Sep 13 '21 22:09 pfichtner

We ended up showing @ragunathjawahar how to write the same test using CombinationApprovals, and thus did not add support for jqwik (yet). I'll bring the topic up next time when we maintainers get together.

LarsEckart avatar Sep 14 '21 10:09 LarsEckart

I'd also love to see jqwik support. I'd also be willing to contribute it.

Is there a way to enhance framework support as some kind of plug-in? This could be the first step before getting it into the core of ApprovalTests.

jlink avatar Aug 03 '22 06:08 jlink

We currently get together on Mondays, 19:00 German time. If that suits you, I can send you an invite. :)

LarsEckart avatar Aug 03 '22 08:08 LarsEckart

Sure. Next Monday would be my last opportunity before vacation time.

jlink avatar Aug 03 '22 08:08 jlink

I sent the invite to [email protected]

LarsEckart avatar Aug 03 '22 09:08 LarsEckart

Thanks.

Am Mi., 3. Aug. 2022 um 11:59 Uhr schrieb Lars Eckart < @.***>:

I sent the invite to @.***

— Reply to this email directly, view it on GitHub https://github.com/approvals/ApprovalTests.Java/issues/189#issuecomment-1203739414, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZMAISXMYHEKLUB4IUFG3VXI7G5ANCNFSM5D6ZLSJA . You are receiving this because you commented.Message ID: @.***>

jlink avatar Aug 03 '22 10:08 jlink

ApprovalTests now also detects test methods that are using jqwik. released as 18.0.0

https://github.com/approvals/ApprovalTests.Java/commit/01be1e0e292f16851d316ad16233d40201946a4d

https://github.com/approvals/ApprovalTests.Java/commit/e70a7d6c3853a6830a5008e6b185bca4c0a6b7da

LarsEckart avatar Aug 09 '22 10:08 LarsEckart

ApprovalTests now also detects test methods that are using jqwik. released as 18.0.0

01be1e0

e70a7d6

Even better. It now detects any test method that uses the JUnit Platform convention of having @Testable in its list of meta-annotations.

jlink avatar Aug 09 '22 10:08 jlink

For real jqwik support, however, jqwik's lifecycle must be considered. I'll have a look into that.

jlink avatar Aug 09 '22 10:08 jlink

I played around a bit and a first approach ended up using a per property lifecycle:

/**
 * Using this handmade lifecycle will check all values at the end,
 * and only if the property succeeds otherwise.
 */
@Property(tries = 11, seed = "42")
@PerProperty(JqwikApprovals.class)
void strings(@ForAll @StringLength(5) @AlphaChars String s) {
	JqwikApprovals.verify(s);
}

It's not the best and most generic approach yet, but I think it proves that the approvals idea can be used within property-based testing.

jlink avatar Aug 10 '22 14:08 jlink

I played around a bit and a first approach ended up using a per property lifecycle:

/**
 * Using this handmade lifecycle will check all values at the end,
 * and only if the property succeeds otherwise.
 */
@Property(tries = 11, seed = "42")
@PerProperty(JqwikApprovals.class)
void strings(@ForAll @StringLength(5) @AlphaChars String s) {
	JqwikApprovals.verify(s);
}

It's not the best and most generic approach yet, but I think it proves that the approvals idea can be used within property-based testing.

Just for reference, I have a small demo project for different test types.

Before the release of approvals 18.0.0 I used an adapted copy of AttributeStackSelector to get approvals work with jqwik, see https://github.com/pfichtner/testtypes/pull/69

With PR 69 I purged the class mentioned and everything seems still to work fine using NamedEnvironment#withParameters

pfichtner avatar Aug 10 '22 15:08 pfichtner

With PR 69 I purged the class mentioned and everything seems still to work fine using NamedEnvironment#withParameters

I assume this creates a file for each try?

jlink avatar Aug 10 '22 15:08 jlink

With PR 69 I purged the class mentioned and everything seems still to work fine using NamedEnvironment#withParameters

I assume this creates a file for each try?

Right, so it does. So I guess this is what you want to prevent 😄

pfichtner avatar Aug 10 '22 16:08 pfichtner

Right, so it does. So I guess this is what you want to prevent 😄

In the ideal world I'd like both:

  • a single file (my solution)
  • early failure (your solution)

I wonder if there's a way to do both without rewriting a lot of the verification logic of ApprovalTests.

jlink avatar Aug 10 '22 16:08 jlink