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

Approval test framework throws error when using it with @TestTemplate #174

Open
pbaeck opened this issue Aug 13, 2021 · 3 comments
Open
Assignees

Comments

@pbaeck
Copy link

pbaeck commented Aug 13, 2021

When I use the Approvals Libary with the TestTemplate Option, like:

@TestTemplate
@ExtendWith(UserIdGeneratorTestInvocationContextProvider.class)
public void whenUserIdRequested_thenUserIdIsReturnedInCorrectFormat(UserIdGeneratorTestCase testCase) {
    UserIdGenerator userIdGenerator = new UserIdGeneratorImpl(testCase.isFeatureEnabled());

    String actualUserId = userIdGenerator.generate(testCase.getFirstName(), testCase.getLastName());

    Assertions.assertEquals(actualUserId, testCase.getExpectedUserId());
    Approvals.verify(actualUserId);
}

It throws the error:

java.lang.RuntimeException: Could not find Junit/TestNg TestCase you are running, supported frameworks: Junit3, Junit4, Junit5, TestNg

The problem is in the function:
org.approvaltests.namer.AttributeStackSelector > AttributeStackSelector (Class is not TestCase when using @testtemplate)

Is there a possibility to use the libary with @testtemplate?

@LarsEckart
Copy link
Contributor

This sounds similar to #171 and I have to admit, that one gave us some trouble. :)

We'll look into it, perhaps already next Monday when we meet again.

@LarsEckart LarsEckart self-assigned this Aug 23, 2021
@LarsEckart
Copy link
Contributor

hello @pbaeck !

getting to a compiling example took us some time, but once we had it, implementing initial support for @testtemplate wasn't too difficult. Have a look at this:

https://github.com/approvals/ApprovalTests.Java/blob/issue-174/approvaltests/src/test/java/org/approvaltests/namer/TestTemplateTest.java#L38

We don't use ApprovalTests there but the resulting string is what ApprovalTests will use as file name for each of the test cases.

What do you think, shall we publish this?

@pbaeck
Copy link
Author

pbaeck commented Aug 30, 2021

Hi Lars,

thank you for your fast response.
I think that will resolve my problem.

I'm looking foward for the new version :)

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

No branches or pull requests

2 participants