简体   繁体   中英

How to retrieve tag value using junit.jupiter?

I am trying to retrieve the tag value using junit5. Is there any way to retrieve below tag value ABC, PQR, XYZ, MNQ in the beforeEach method using Junit5?

 @WIP
 @SMOKE
 @PENDING

 @Tags(value = {@Tag("ABC"),@Tag("PQR"),@Tag("XYZ"), @Tag("MNQ"))})
 public void TestMethod() {
       Launch()
 }

You can do so by declaring org.junit.jupiter.api.TestInfo as a method parameter of your @BeforeEach method.

public class TestTest {

    @BeforeEach
    public void before(TestInfo testInfo) {
        System.out.println(testInfo.getTags());
    }

    @Test
    @Tags(value = {@Tag("ABC"), @Tag("PQR"), @Tag("XYZ"), @Tag("MNQ")})
    public void TestMethod() {
    }
}

Prints out

[ABC, PQR, XYZ, MNQ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM