Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit's TestFactory not supported with Kotlin lambdas #617

Closed
atetzner opened this issue Feb 18, 2025 · 1 comment
Closed

JUnit's TestFactory not supported with Kotlin lambdas #617

atetzner opened this issue Feb 18, 2025 · 1 comment

Comments

@atetzner
Copy link

With issue #234 the support for JUnit's @TestFactory annotation in conjunction with a Kotlin lambda has been implemented. Unfortunately, this seems to be broken as exactly the test that is mentioned in this issue does not work any more: It fails with

java.lang.RuntimeException: Could not find Junit/TestNg TestCase you are running, supported frameworks: Junit3, Junit4, Junit5, TestNg
	at org.approvaltests.namer.AttributeStackSelector.selectElement(AttributeStackSelector.java:69)
	at com.spun.util.tests.TestUtils.getCurrentFileForMethod(TestUtils.java:181)
	at com.spun.util.tests.TestUtils.getCurrentFileForMethod(TestUtils.java:174)
	at org.approvaltests.namer.StackTraceNamer.<init>(StackTraceNamer.java:17)
	at org.approvaltests.Approvals$1.load(Approvals.java:46)
	at org.approvaltests.Approvals$1.load(Approvals.java:43)
	at org.approvaltests.Approvals.createApprovalNamer(Approvals.java:278)
	at com.spun.util.ArrayUtils.getOrElse(ArrayUtils.java:309)
	at org.approvaltests.core.Options$FileOptions.getNamer(Options.java:120)
	at org.approvaltests.Approvals.verify(Approvals.java:196)
	at org.approvaltests.Approvals.verify(Approvals.java:55)
	at org.approvaltests.Approvals.verify(Approvals.java:64)
	at org.approvaltests.Approvals.verify(Approvals.java:59)
	at org.example.ApprovalTest.test_factory$lambda$1$lambda$0(AppTest.kt:19)

It would be great to have this supported (fixed?) as this would reduce the amount of tests that only differ in slight details.

If it helps, I can provide a sample project with a test.

Don't know if it is relevant, but issue #171 that should add general support for @TestFactory annotation (?) is still open. The mentioned workaround in the last comment to add @Testable annotation does at least here not work.

@ScottBob
Copy link
Contributor

Wow! This was a hard one to figure out! It turns out this actually works, but there are two things you need to do. We wrote some documentation here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants