Class StackTraceTestFinderUtil

java.lang.Object
org.approvej.approve.StackTraceTestFinderUtil

@NullMarked public class StackTraceTestFinderUtil extends Object
Utility class to find the current test method using the stack trace.
  • Method Summary

    Modifier and Type
    Method
    Description
    static TestMethod
    Finds the current test method using the stack trace.
    static Path
    Finds the source path of the test method, making the following assumptions: the top-level enclosing class' name is also the name of the source file (for nested or inner classes, the enclosing class hierarchy is walked up to find the top-level class), the base package is at most 10 levels deep, the filename extension of the file is java, kt, groovy , or scala

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • currentTestMethod

      public static TestMethod currentTestMethod()
      Finds the current test method using the stack trace.
      Returns:
      the currently executing test Method
    • findTestSourcePath

      public static Path findTestSourcePath(Method testMethod)
      Finds the source path of the test method, making the following assumptions:
      • the top-level enclosing class' name is also the name of the source file (for nested or inner classes, the enclosing class hierarchy is walked up to find the top-level class),
      • the base package is at most 10 levels deep,
      • the filename extension of the file is java, kt, groovy , or scala
      Parameters:
      testMethod - the test Method
      Returns:
      the Path to the source file containing the given testMethod