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

@Test alongside Lombok's @Delegate annotation?! #1457

Closed
wheredevel opened this issue May 22, 2017 · 3 comments
Closed

@Test alongside Lombok's @Delegate annotation?! #1457

wheredevel opened this issue May 22, 2017 · 3 comments

Comments

@wheredevel
Copy link

wheredevel commented May 22, 2017

Guys, I repost my issue with Lombok and JUnit.
Issue: projectlombok/lombok#1356

I believe It's a cool feature actually (saves me alot of time, but need to workaround the @Test annotation limitation):

Original

Hi, guys!

I'm mixing-in a "template" test into an "origin" test.
Something like:

public interface TestSomething {
  void testSomething() throws Exception;

  @Builder
  public static final class Mixin {
    public void testSomething() throws Exception {
      // some actual test here
    }
  }
}

public class MyTest {
  @Delegate
  private TestSomething testSomething = TestSomething.Mixin.builder().build();
}

(Note: I omitted a way I pass MyTest context to the Mixin - it's an important part, but irrelevant to the issue subject.)

So, the question is:
How do I make JUnit discover the testSomething() of the origin, generated by @Delegate, as a test - like it was annotated with @Test ?

Followup

So, guys, how hard is it to allow @Test annotation near the @Delegate one?:

public class MyTest {
  @Delegate
  @Test 
  private TestSomething testSomething = TestSomething.Mixin.builder().build();
}

I guess, adding an onMethod to @Delegate is a dream come true:

public class MyTest {
  @Delegate(onMethod=@__({@Test}))
  private TestSomething testSomething = TestSomething.Mixin.builder().build();
}
@panchenko
Copy link
Contributor

JUnit runs the methods annotated with @Test, if your tool generates those automatically - it should also generate this annotation, then it would work out of the box. There is nothing JUnit should do in this case.

Also, on JUnit4 side additional ways to discover tests can be implemented in an runner.

Another approach would be posting a question on StackOverflow and describing the problem your trying to solve instead of a particular approach. You might get some new ideas then.

@wheredevel
Copy link
Author

My idea of posting this here, is about to show how JUnit tests can be templated and mixed-in easily using Lombok - and, hopefully, to push the community to closing this small gap.

@kcooney
Copy link
Member

kcooney commented May 23, 2017

We would be unlikely to add support for.Lombok in JUnit 4.x (we currently still depend on JDK 5!)

If you cannot generate methods annotated with @Test you could create a runner that extends BlockJUnit4ClassRunner to find the methods.

It is possible that JUnit 5 would have better extension points for allowing you identify these methods as test methods.

@kcooney kcooney closed this as completed May 23, 2017
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

3 participants