Thursday, 5 July 2018

Junit: TestName rule: get the test case name under execution

The TestName Rule makes the current test name available inside test method.




Find the below working application.

TestApp.java
package com.sample.test;

import static org.junit.Assert.assertEquals;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

public class TestApp {
 @Rule
 public TestName testName = new TestName();

 @Test
 public void testCase1() {
  assertEquals("testCase1", testName.getMethodName());
 }

 @Test
 public void testCase2() {
  assertEquals("testCase2", testName.getMethodName());
 }

}




Previous                                                 Next                                                 Home

No comments:

Post a Comment