• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package testhelper;
2 
3 /**
4  * <code>OutputDirectoryPatch</code> is a helper class to provide an output directory
5  * for TestNG tests that explicitly create an instance of TestNG and do not know the
6  * output directory specified for the test.
7  *
8  * @author cquezel
9  * @since 4.8
10  */
11 public final class OutputDirectoryPatch {
12 
13   /** The default output directory name if none was specified. We should use something
14    * different than "test-output" to make it clear that the output directory
15    * has not been set. */
16   private static final String DEFAULT_OUTPUT_DIRECTORY = "test-output";
17 
18   /** The name of the System property used to store the output directory. */
19   private static final String OUTPUT_DIRECTORY_PROPERTY_NAME = "testng.outputDir";
20 
21   /**
22    * Private constructor to disable instantiation.
23    *
24    * @since 4.8
25    */
OutputDirectoryPatch()26   private OutputDirectoryPatch() {
27     // Hide constructor
28   }
29 
30   /**
31    * Returns the output directory as specified for the current test.
32    *
33    * @return the output directory as specified for the current test.
34    * @since 4.8
35    */
getOutputDirectory()36   public static String getOutputDirectory() {
37     String tmp = System.getProperty(OUTPUT_DIRECTORY_PROPERTY_NAME);
38     if (tmp != null) {
39       return tmp;
40     }
41 //    System.err.println("System property: " + OUTPUT_DIRECTORY_PROPERTY_NAME
42 //        + " has not been set. Using default path: " + DEFAULT_OUTPUT_DIRECTORY);
43 
44 //    new Throwable("Stack is only to help locate the problem. No excpetion thrown.").printStackTrace(System.err);
45     return DEFAULT_OUTPUT_DIRECTORY;
46   }
47 }
48