Skip to content

@IgnoreUntil class annotation is required and overrides method annotation #3

@siladu

Description

@siladu

@IgnoreUntil("2099-01-01") has to be declared on the class for this rule to work at all.
It would be better if it was optional and just having a method annotation also worked.

public class IgnoreUntilTest {

    @Rule public IgnoreUntilRule rule = new IgnoreUntilRule();

    @IgnoreUntil("2099-01-01")
    @Test
    public void wantToIgnore() {
        Assert.fail();
    }
}

When @IgnoreUntil("2099-01-01") is declared on the class, it's value will be used on all methods that are also annotated with @IgnoreUntil.
This is fine if you want to share a date across a subset of the tests.
Not great if you also want to specify a date at the test level.

A better solution would allow shouldNowExecute() to be ignored based on the @IgnoreUntil("2018-01-01") annotation rather than the class annotation.

@IgnoreUntil("2099-01-01")
public class IgnoreUntilTest {

    @Rule public IgnoreUntilRule rule = new IgnoreUntilRule();

    @IgnoreUntil
    @Test
    public void wantToIgnore() {
        Assert.fail();
    }

    @IgnoreUntil
    @Test
    public void wantToIgnore2() {
        Assert.fail();
    }

    @IgnoreUntil("2018-01-01")
    @Test(expected = AssertionError.class)
    public void shouldNowExecute() {
        // this incorrectly 'passes' due to being ignored rather than AssertionError
        Assert.fail();
    }

    @Test(expected = AssertionError.class)
    public void dontIgnore() {
        Assert.fail();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions