1

In my Abstract class I have this code line :

@Rule
  public final TestName testName = new TestName();

That is used in some tests to pass the specific method the name, for example:

@Test
public void assertApiUp() {
    sendTest(testName.getMethodName(),true);
}

How do you manage this in junit 5 with TestInfo? I was thinking add in my set up method @BeforeEach void setUp(TestContext context, TestInfo testInfo){deploy(context,testInfo)}

or do you think is better in each testClass, for instance:

 @Test
  @DisplayName("assertApiUp")
  public void assertApiUp(TestInfo testInfo) {...}

And another doubt, how do you put this other piece of code in junit 5 :

 @Rule
    public TestRule doOnfail = new TestWatcher() {
    @Override
    protected void failed(Description desc) {
     stopAllRunningContainers();
    }

Thanks in advance guys!

mononoke83
  • 342
  • 2
  • 16
  • Check this answer https://stackoverflow.com/a/51012642/3287786. – I.G. Jul 02 '20 at 16:40
  • 1
    The best way depends on what you want to do with the test name. So what is your intention? – johanneslink Jul 02 '20 at 19:18
  • Thanks @johanneslink, I've edit a bit more my question, but as I've mentionated there,it's an abstract test class,then you can imagine that it's to use a common behavior features in the tests. – mononoke83 Jul 03 '20 at 10:42

0 Answers0