{"action":"created","issue":{"url":"https://api.github.com/repos/junit-team/junit5/issues/415","repository_url":"https://api.github.com/repos/junit-team/junit5","labels_url":"https://api.github.com/repos/junit-team/junit5/issues/415/labels{/name}","comments_url":"https://api.github.com/repos/junit-team/junit5/issues/415/comments","events_url":"https://api.github.com/repos/junit-team/junit5/issues/415/events","html_url":"https://github.com/junit-team/junit5/issues/415","id":166387555,"number":415,"title":"Test class with all test methods @Disabled shouldn't run @BeforeAll / @AfterAll methods","user":{"login":"thomasdarimont","id":314690,"avatar_url":"https://avatars.githubusercontent.com/u/314690?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasdarimont","html_url":"https://github.com/thomasdarimont","followers_url":"https://api.github.com/users/thomasdarimont/followers","following_url":"https://api.github.com/users/thomasdarimont/following{/other_user}","gists_url":"https://api.github.com/users/thomasdarimont/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasdarimont/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasdarimont/subscriptions","organizations_url":"https://api.github.com/users/thomasdarimont/orgs","repos_url":"https://api.github.com/users/thomasdarimont/repos","events_url":"https://api.github.com/users/thomasdarimont/events{/privacy}","received_events_url":"https://api.github.com/users/thomasdarimont/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-19T17:25:23Z","updated_at":"2016-07-20T05:15:04Z","closed_at":null,"body":"Currently the 5.0.0-M1 test class Methods annotated with `@BeforeAll` and `@AfterAll` are executed even if the Test class only contains @Disabled methods.\r\n\r\nI would expect that those `@BeforeAll` and `@AfterAll` are only executed if there is work to do e.g. prepare an environment for tests and clean-up afterwards.\r\n\r\n```java\r\npackage demo;\r\n\r\n\r\nimport org.junit.jupiter.api.AfterAll;\r\nimport org.junit.jupiter.api.AfterEach;\r\nimport org.junit.jupiter.api.BeforeAll;\r\nimport org.junit.jupiter.api.BeforeEach;\r\nimport org.junit.jupiter.api.Disabled;\r\nimport org.junit.jupiter.api.Test;\r\n\r\nimport static org.junit.jupiter.api.Assertions.assertTrue;\r\n\r\n/**\r\n * Created by tom on 19.07.16.\r\n */\r\npublic class Junit5TestLifeCycleMethods {\r\n\r\n    @BeforeAll\r\n    static void beforeAll() {\r\n        System.out.println(\"Before all\");\r\n    }\r\n\r\n    @BeforeEach\r\n    void beforeEach() {\r\n        System.out.println(\"Before each\");\r\n    }\r\n\r\n    @AfterEach\r\n    void afterEach() {\r\n        System.out.println(\"After each\");\r\n    }\r\n\r\n    @AfterAll\r\n    static void afterAll() {\r\n        System.out.println(\"After all\");\r\n    }\r\n\r\n    @Test\r\n    @Disabled\r\n    void someTest() {\r\n        System.out.println(\"run someTest\");\r\n        assertTrue(true);\r\n    }\r\n\r\n    @Test\r\n    @Disabled\r\n    void anotherTest() {\r\n        System.out.println(\"run anotherTest\");\r\n        assertTrue(true);\r\n    }\r\n}\r\n``` \r\n\r\nOutputs in idea:\r\n```\r\nINFO: Discovered TestEngines with IDs: [junit-vintage, junit-jupiter]\r\nEmpty test suite.\r\nBefore all\r\n\r\nOptional[void demo.Junit5TestLifeCycleMethods.anotherTest()] is @Disabled\r\nAfter all\r\nProcess finished with exit code 0\r\n```\r\n\r\nMaven Dependencies used:\r\n```xml\r\n<dependencies>\r\n        <!-- JUnit 5-->\r\n        <dependency>\r\n            <groupId>org.junit.jupiter</groupId>\r\n            <artifactId>junit-jupiter-api</artifactId>\r\n            <version>5.0.0-M1</version>\r\n            <scope>test</scope>\r\n        </dependency>\r\n\r\n        <dependency>\r\n            <groupId>org.junit.vintage</groupId>\r\n            <artifactId>junit-vintage-engine</artifactId>\r\n            <version>4.12.0-M1</version>\r\n        </dependency>\r\n    </dependencies>\r\n```"},"comment":{"url":"https://api.github.com/repos/junit-team/junit5/issues/comments/233840186","html_url":"https://github.com/junit-team/junit5/issues/415#issuecomment-233840186","issue_url":"https://api.github.com/repos/junit-team/junit5/issues/415","id":233840186,"user":{"login":"mmichaelis","id":71911,"avatar_url":"https://avatars.githubusercontent.com/u/71911?v=3","gravatar_id":"","url":"https://api.github.com/users/mmichaelis","html_url":"https://github.com/mmichaelis","followers_url":"https://api.github.com/users/mmichaelis/followers","following_url":"https://api.github.com/users/mmichaelis/following{/other_user}","gists_url":"https://api.github.com/users/mmichaelis/gists{/gist_id}","starred_url":"https://api.github.com/users/mmichaelis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmichaelis/subscriptions","organizations_url":"https://api.github.com/users/mmichaelis/orgs","repos_url":"https://api.github.com/users/mmichaelis/repos","events_url":"https://api.github.com/users/mmichaelis/events{/privacy}","received_events_url":"https://api.github.com/users/mmichaelis/received_events","type":"User","site_admin":false},"created_at":"2016-07-20T05:15:04Z","updated_at":"2016-07-20T05:15:04Z","body":"I agree with you that this would be nice. But aren't the ways a test can be skipped just too varied? For example we don't use an annotation `@Ignored` (`@Disabled`) nowadays but *custom annotations* like:\r\n\r\n* `@Label(\"known-issue-XYZ\")` to ignore tests with a given label unless a system property is set (`labelCondition=skip`) or\r\n* `@Browser(include='firefox', exclude={'chrome','internet explorer'})`\r\n\r\nOther tests are ignored by assumption failures raised just within the test.\r\n\r\nSo I think with these various ways to skip a test there is no obvious solution at hand how to deal with this problem but tell the one who disabled all tests to possibly already do this on class level (oh, of course this should work: If a test class is marked as disabled BeforeAll, AfterAll should not run).\r\n\r\nAnd even if we had a solution for this: There are also various ways (at least two, I think) to have code executed before and after all test like implementing the appropriate callbacks (`BeforeAllCallback`, `AfterAllCallback`).\r\n\r\nSo while I think your idea is nice and desirable I don't see an easy solution to that. You possibly could make the implementation of `@BeforeAll` lazy and trigger it in `@BeforeEach` and it contains code to execute only once. And in addition to that of course `@AfterAll` only executes the clean-up code if the `@BeforeAll` had actually been triggered."}}
{"actor":{"display_login":"mmichaelis"}}