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

Allow JUnit rules plugin to support individually annotated tests #79

Open
ashleyfrieze opened this issue Dec 7, 2016 · 0 comments
Open

Comments

@ashleyfrieze
Copy link
Contributor

In native JUnit, you can do something like this:

@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void willDoSomethingDestructiveToSpring() throws Exception {
    myBean.deleteAll();
}

The @DirtiesContext annotation is a clue to the JUnit runner or @Rule that the test method needs some variation in its treatment.

With #56 it is possible to use different mix-in objects to run JUnit rules differently in different parts of the spec. However, making a single it have different behaviour to another is not possible. This is largely because under the hood all tests appear to relate to a stub @Test public void stub() {} method.

Perhaps it would be possible to fix this by one of two ways:

// provide annotated test methods in the Mixin
public class Mixin {
   // rules stuff here

  @Test
  @InterestngAnnotation("1")
  public void interesting1() {
  }

  @Test
  @InterestngAnnotation("2")
  public void interesting2() {
  }
}

// and then in the spec refer to them

Supplier<Mixin> mixin = applyRules(Mixin.class);
describe("some suite", () -> {
  it("uses the mixin a particular way", with(methodSetup("interesting1"), () -> {
    // test something
  }));
});

An alternative is to provide the method selection when applying the rules:

Supplier<Mixin> mixin = applyRules(Mixin.class, "interesting1");
describe("some suite", () -> {
  it("uses the mixin a particular way", () -> {
    // test something
  });
});

More suggestions needed, I think.

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

1 participant