import org.junit.Rule; public class NameRuleTest { @Rule public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } @Test public void testB() { assertEquals("testB", name.getMethodName()); } }
public abstract class BaseTestClass { @ClassRule public static TestClassName className = new TestClassName(); @Rule public TestName testName = new TestName(); @BeforeClass public static void printClassName() { System.out.println("--" + className.getClassName() + "--"); } @Before public void printMethodName() { System.out.print(" " + testName.getMethodName()); } @After public void printNewLine() { System.out.println(); } }
/** * If not enforced, the repeat rule applies only if the test is run in non-debug mode. */ public static TestRule getRepeatRule(final boolean enforce) { return enforce || !IS_DEBUG ? new RepeatTestRule() : new TestName(); }
public static TestRule getTimeoutRule(int timeout) { return IS_DEBUG ? new TestName() : Timeout.millis(timeout); }
/** constructor */ public TestMajorCompaction(String compType) { super(); name = new TestName(); // Set cache flush size to 1MB conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024*1024); conf.setInt(HConstants.HREGION_MEMSTORE_BLOCK_MULTIPLIER, 100); compactionThreshold = conf.getInt("hbase.hstore.compactionThreshold", 3); conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(compType)); secondRowBytes = START_KEY_BYTES.clone(); // Increment the least significant character so we get to next row. secondRowBytes[START_KEY_BYTES.length - 1]++; thirdRowBytes = START_KEY_BYTES.clone(); thirdRowBytes[START_KEY_BYTES.length - 1] = (byte) (thirdRowBytes[START_KEY_BYTES.length - 1] + 2); }
@SuppressWarnings("InstanceMethodNamingConvention") @ContextConfiguration(classes = {ServiceTest.class}) public class SpringAwareTest { @ClassRule public static final SpringAware SPRING_AWARE = SpringAware.forClass(SpringAwareTest.class); @Rule public TestRule springAwareMethod = SPRING_AWARE.forInstance(this); @Rule public TestName testName = new TestName(); ... }
public class JUnitTest { @Rule public TestName testName = new TestName(); @Before public void before() { System.out.println(testName.getMethodName()); } @Test public void test() { System.out.println("test ..."); } }
public class NameRuleTest { @Rule public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } @Test public void testB() { assertEquals("testB", name.getMethodName()); } }
@RunWith(Interceptors.class) public class NameTest { @Interceptor public TestName name = new TestName(); @Test public void funnyName() { assertEquals("funnyName", name.getMethodName()); } }
public class TestCaseExample { @Rule public TestName testName = new TestName(); @Before public void setUp() { Method m = TestCaseExample.class.getMethod(testName.getMethodName()); ... } ...
/** * If not enforced, the repeat rule applies only if the test is run in non-debug mode. */ public static TestRule getRepeatRule(final boolean enforce) { return enforce || !IS_DEBUG ? new RepeatTestRule() : new TestName(); }
@Rule public TestName name = new TestName(); @Before public void setup() { if(listOfTestNeedSetup.contains(name.getMethodName()) { // need setup } }
@Rule public TestName name = new TestName(); @Test public void test() { assertEquals("test", name.getMethodName()); }
public class MyTest { @Rule public TestName name = new TestName(); @Before public void before() { System.out.println("running...", name.getMethodName()); } }
public class MyTest { @Rule public TestName testName = new TestName(); @Before public void setUp() { assumeTrue(testName.getMethodName().equals("myMethodName")); // setup follows } }
@Rule public TestName testName = new TestName(); public URL url; @Before public void setup() { String resourceName = testName.getMethodName().substring(4).toLowerCase(); url = getClass().getResource("/" + resourceName + ".txt"); } @Test public void testResource1() { // snip } @Test public void testResource2() { // snip }
public class NameRuleTest { @Rule public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } @Test public void testB() { assertEquals("testB", name.getMethodName()); } }
public class NameRuleTest { @Rule public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } @Test public void testB() { assertEquals("testB", name.getMethodName()); } }
public static TestRule getTimeoutRule(int timeout, TimeUnit unit) { return IS_DEBUG ? new TestName() : Timeout.builder().withTimeout(timeout, unit).build(); }
/** constructor */ public TestMajorCompaction(String compType) { super(); name = new TestName(); // Set cache flush size to 1MB conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024*1024); conf.setInt(HConstants.HREGION_MEMSTORE_BLOCK_MULTIPLIER, 100); compactionThreshold = conf.getInt("hbase.hstore.compactionThreshold", 3); conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(compType)); secondRowBytes = START_KEY_BYTES.clone(); // Increment the least significant character so we get to next row. secondRowBytes[START_KEY_BYTES.length - 1]++; thirdRowBytes = START_KEY_BYTES.clone(); thirdRowBytes[START_KEY_BYTES.length - 1] = (byte) (thirdRowBytes[START_KEY_BYTES.length - 1] + 2); }