Class AbstractTestCase

  • Direct Known Subclasses:
    AbstractHtmlUnitScriptTestCase, AbstractWebDriverTestCase

    public abstract class AbstractTestCase
    extends java.lang.Object
    AbstractTestCase is the base class for all load test cases. The purpose of this class is to perform some internal housekeeping tasks once the test case has finished. This includes:
    • logging of collected results to disk
    • flushing any caches
    If your test cases do not inherit from this class, the system does not break, but you will loose some of the features, e.g. logging the results collected during the test case.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void __setup()
      Executes base setup of the test case.
      void __tearDown()
      Executes base tear-down of the test case.
      protected java.lang.String getEffectiveKey​(java.lang.String bareKey)
      Returns the effective key to be used for property lookup via one of the getProperty(...) methods.
      java.lang.String getProperty​(java.lang.String key)
      Returns the value for the given key as configured in the test suite configuration.
      boolean getProperty​(java.lang.String key, boolean defaultValue)
      Returns the value for the given key as configured in the test suite configuration.
      int getProperty​(java.lang.String key, int defaultValue)
      Returns the value for the given key as configured in the test suite configuration.
      java.lang.String getProperty​(java.lang.String key, java.lang.String defaultValue)
      Returns the value for the given key as configured in the test suite configuration.
      protected java.lang.String getSimpleName()
      Returns the test name.
      java.util.Map<java.lang.String,​java.lang.String> getTestDataSet()
      Returns the test data set to use when running the test script.
      protected java.lang.String getTestName()
      Returns the test name.
      java.lang.String reconfigureStartUrl​(java.lang.String urlString)
      Returns the actual start URL to be used for the test based on the given URL and the local configuration.
      void setTestDataSet​(java.util.Map<java.lang.String,​java.lang.String> testDataSet)
      Sets the test data set to use when running the test case.
      protected void setTestName()
      Deprecated.
      will be removed in XLT 4.6.
      protected void setTestName​(java.lang.String testName)
      Sets the test name.
      void setUp()
      Executes basic setup of the test case.
      void tearDown()
      Executes the basic tear down for the test case.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractTestCase

        public AbstractTestCase()
    • Method Detail

      • __setup

        public final void __setup()
        Executes base setup of the test case.
      • __tearDown

        public final void __tearDown()
        Executes base tear-down of the test case.
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Returns the value for the given key as configured in the test suite configuration. The process of looking up a property uses multiple fall-backs. When resolving the value for the key "password", for example, the following effective keys are tried, in this order:
        1. the test user name plus simple key, e.g. "TAuthor.password"
        2. the test class name plus simple key, e.g. "com.xceptance.xlt.samples.tests.TAuthor.password"
        3. the simple key, e.g. "password"
        This multi-step hierarchy allows for test-user-specific or test-case-specific overrides of certain settings, while falling back to the globally defined values if such specific settings are absent.
        Parameters:
        key - the simple property key
        Returns:
        the property value, or null if not found
      • getProperty

        public boolean getProperty​(java.lang.String key,
                                   boolean defaultValue)
        Returns the value for the given key as configured in the test suite configuration. See getProperty(String) for a description of the look-up logic. This method returns the passed default value if the property value could not be found.
        Parameters:
        key - the property key
        defaultValue - the default value
        Returns:
        the property value as a boolean
      • getProperty

        public int getProperty​(java.lang.String key,
                               int defaultValue)
        Returns the value for the given key as configured in the test suite configuration. See getProperty(String) for a description of the look-up logic. This method returns the passed default value if the property value could not be found.
        Parameters:
        key - the property key
        defaultValue - the default value
        Returns:
        the property value as an int
      • getProperty

        public java.lang.String getProperty​(java.lang.String key,
                                            java.lang.String defaultValue)
        Returns the value for the given key as configured in the test suite configuration. See getProperty(String) for a description of the look-up logic. This method returns the passed default value if the property value could not be found.
        Parameters:
        key - the property key
        defaultValue - the default value
        Returns:
        the property value
      • getTestDataSet

        public java.util.Map<java.lang.String,​java.lang.String> getTestDataSet()
        Returns the test data set to use when running the test script. Call this method from your test code to get access to the test data set for this test run.
        Returns:
        the test data
      • reconfigureStartUrl

        public java.lang.String reconfigureStartUrl​(java.lang.String urlString)
                                             throws java.lang.Exception
        Returns the actual start URL to be used for the test based on the given URL and the local configuration. This method reconfigures the given URL to contain "user-local" settings instead. This is especially useful if a test has been created/recorded on one system, but should later be run on another system without changing the code.

        Typically, a URL looks like this:

         <protocol>://[<userInfo>@]<host>[:<port>][<path>][?<query>][#<ref>]
         
        Each part of the URL can be overwritten individually by local configuration. Typically, this makes sense for protocol, userInfo, host, and port only. In order to override the values from the given URL, one has to provide appropriate settings in the XLT configuration. Using the following example configuration, host and port of the original URL will be replaced:
         #startUrl.protocol = http
         #startUrl.userInfo =
         startUrl.host = myhost
         startUrl.port = 81
         #startUrl.path =
         #startUrl.query =
         #startUrl.ref =
         
        All other parts of the URL are left as they are.
        Parameters:
        urlString - the original URL string
        Returns:
        the reconfigured URL
        Throws:
        java.lang.Exception - this is just declared to enable classes overwriting this method to throw an appropriate exception, the basic implementation only throws a MalformedURLException if the argument URL string is invalid, or if the resulting URL is invalid due to illegal values in the configuration
      • setTestDataSet

        public void setTestDataSet​(java.util.Map<java.lang.String,​java.lang.String> testDataSet)
        Sets the test data set to use when running the test case. This method is called by the XLT test case runner to provide the test data set for this test run, retrieved from a DataSetProvider instance.
        Parameters:
        testDataSet - the test data
      • setUp

        public void setUp()
        Executes basic setup of the test case. Mainly reports the beginning of the execution to the log. Can be overwritten to get rid of the message.
      • tearDown

        public void tearDown()
        Executes the basic tear down for the test case. Mainly reports the end of the execution to the log. Can be overwritten to get rid of the message.
      • getEffectiveKey

        protected java.lang.String getEffectiveKey​(java.lang.String bareKey)
        Returns the effective key to be used for property lookup via one of the getProperty(...) methods.

        When looking up a key, "password" for example, the following effective keys are tried, in this order:

        1. the test user name plus simple key, e.g. "TAuthor.password"
        2. the test class name plus simple key, e.g. "com.xceptance.xlt.samples.tests.TAuthor.password"
        3. the simple key, e.g. "password"
        Parameters:
        bareKey - the bare property key, i.e. without any prefixes
        Returns:
        the first key that produces a result
      • getSimpleName

        protected java.lang.String getSimpleName()
        Returns the test name.
        Returns:
        test name
      • getTestName

        protected java.lang.String getTestName()
        Returns the test name. If no custom name was set this is the class name.
        Returns:
        test name
      • setTestName

        @Deprecated
        protected void setTestName()
        Deprecated.
        will be removed in XLT 4.6. Test case name will be set via constructor.
        Sets the test name.
      • setTestName

        protected void setTestName​(java.lang.String testName)

        Sets the test name.

        It's highly recommended to call this method in the constructor body only.

        Parameters:
        testName - test name