/** * Using junit 3.x naming standards for unit tests and test method names, attempt to discover the * unit test name from the execution stack. * * @return the unit test id found via execution stack and junit 3.8 naming conventions. * @see #getTestIDAsPath() */ private static TestID getTestID() { StackTraceElement stacked[] = new Throwable().getStackTrace(); for (StackTraceElement stack : stacked) { if (stack.getClassName().endsWith("Test")) { if (stack.getMethodName().startsWith("test")) { TestID testid = new TestID(); testid.classname = stack.getClassName(); testid.methodname = stack.getMethodName(); return testid; } } } // If we have reached this point, we have failed to find the test id String LN = System.getProperty("line.separator"); StringBuilder err = new StringBuilder(); err.append("Unable to find a TestID from a testcase that "); err.append("doesn't follow the standard naming rules."); err.append(LN); err.append("Test class name must end in \"*Test\"."); err.append(LN); err.append("Test method name must start in \"test*\"."); err.append(LN); err.append("Call to ").append(MavenTestingUtils.class.getSimpleName()); err.append(".getTestID(), must occur from within stack frame of "); err.append("test method, not @Before, @After, @BeforeClass, "); err.append("@AfterClass, or Constructors of test case."); Assert.fail(err.toString()); return null; }