Class JUnitSampler

All Implemented Interfaces:
Serializable, Cloneable, ConfigMergabilityIndicator, Searchable, Sampler, org.apache.jmeter.testelement.TestElement, ThreadListener

public class JUnitSampler extends AbstractSampler implements ThreadListener
This is a basic implementation that runs a single test method of a JUnit test case. The current implementation will use the string constructor first. If the test class does not declare a string constructor, the sampler will try empty constructor.
See Also:
  • Constructor Details

    • JUnitSampler

      public JUnitSampler()
  • Method Details

    • setClassname

      public void setClassname(String className)
      Sets the Classname attribute of the JavaConfig object
      className - the new Classname value
    • getClassname

      public String getClassname()
      Gets the Classname attribute of the JavaConfig object
      the Classname value
    • setConstructorString

      public void setConstructorString(String constr)
      Set the string label used to create an instance of the test with the string constructor.
      constr - the string passed to the constructor
    • getConstructorString

      public String getConstructorString()
      the string passed to the string constructor
    • getMethod

      public String getMethod()
      the name of the method to test
    • setMethod

      public void setMethod(String methodName)
      Method should add the JUnit testXXX method to the list at the end, since the sequence matters.
      methodName - name of the method to test
    • getSuccess

      public String getSuccess()
      the success message
    • setSuccess

      public void setSuccess(String success)
      set the success message
      success - message to be used for success
    • getSuccessCode

      public String getSuccessCode()
      the success code defined by the user
    • setSuccessCode

      public void setSuccessCode(String code)
      Set the success code. The success code should be unique.
      code - unique success code
    • getFailure

      public String getFailure()
      the failure message
    • setFailure

      public void setFailure(String fail)
      set the failure message
      fail - the failure message
    • getFailureCode

      public String getFailureCode()
      The failure code that is used by other components
    • setFailureCode

      public void setFailureCode(String code)
      Provide some unique code to denote a type of failure
      code - unique code to denote the type of failure
    • getError

      public String getError()
      the descriptive error for the test
    • setError

      public void setError(String error)
      provide a descriptive error for the test method. For a description of the difference between failure and error, please refer to the junit faq
      error - the description of the error
    • getErrorCode

      public String getErrorCode()
      the error code for the test method. It should be an unique error code.
    • setErrorCode

      public void setErrorCode(String code)
      Provide an unique error code for when the test does not pass the assert test.
      code - unique error code
    • getFilterString

      public String getFilterString()
      the comma separated string for the filter
    • setFilterString

      public void setFilterString(String text)
      set the filter string in comma separated format
      text - comma separated filter
    • getDoNotSetUpTearDown

      public boolean getDoNotSetUpTearDown()
      if the sample shouldn't call setup/teardown, the method returns true. It's meant for onetimesetup and onetimeteardown.
      flag whether setup/teardown methods should not be called
    • setDoNotSetUpTearDown

      public void setDoNotSetUpTearDown(boolean setup)
      set the setup/teardown option
      setup - flag whether the setup/teardown methods should not be called
    • getAppendError

      public boolean getAppendError()
      If append error is not set, by default it is set to false, which means users have to explicitly set the sampler to append the assert errors. Because of how junit works, there should only be one error
      flag whether errors should be appended
    • setAppendError

      public void setAppendError(boolean error)
      Set whether to append errors or not.
      error - the setting to apply
    • getAppendException

      public boolean getAppendException()
      If append exception is not set, by default it is set to false. Users have to explicitly set it to true to see the exceptions in the result tree.
      flag whether exceptions should be appended to the result tree
    • setAppendException

      public void setAppendException(boolean exc)
      Set whether to append exceptions or not.
      exc - the setting to apply.
    • getJunit4

      public boolean getJunit4()
      Check if JUnit4 (annotations) are to be used instead of the JUnit3 style (TestClass and specific method names)
      true if JUnit4 (annotations) are to be used. Default is false.
    • setJunit4

      public void setJunit4(boolean junit4)
      Set whether to use JUnit4 style or not.
      junit4 - true if JUnit4 style is to be used.
    • sample

      public SampleResult sample(Entry entry)
      Obtains statistics about the given Entry, and packages the information into a SampleResult.
      Specified by:
      sample in interface Sampler
      entry - the Entry (TODO seems to be unused)
      information about the sample
    • threadFinished

      public void threadFinished()
      Description copied from interface: ThreadListener
      Called for each thread after all samples have been processed. See org.apache.jmeter.threads.JMeterThread#threadFinished(org.apache.jmeter.engine.event.LoopIterationListener)
      Specified by:
      threadFinished in interface ThreadListener
    • threadStarted

      public void threadStarted()
      Set up all variables that don't change between samples.
      Specified by:
      threadStarted in interface ThreadListener
    • setCreateOneInstancePerSample

      public void setCreateOneInstancePerSample(boolean createOneInstancePerSample)
      createOneInstancePerSample - flag whether a new instance for each call should be created
    • getCreateOneInstancePerSample

      public boolean getCreateOneInstancePerSample()
      boolean create New Instance For Each Call