Apache JMeter

org.apache.jmeter.protocol.java.sampler
Class JUnitSampler

java.lang.Object
  extended by org.apache.jmeter.testelement.AbstractTestElement
      extended by org.apache.jmeter.samplers.AbstractSampler
          extended by org.apache.jmeter.protocol.java.sampler.JUnitSampler
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Sampler, TestElement

public class JUnitSampler
extends AbstractSampler

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:
Serialized Form

Field Summary
static java.lang.String APPEND_ERROR
           
static java.lang.String APPEND_EXCEPTION
           
static java.lang.String CLASSNAME
          Property key representing the classname of the JavaSamplerClient to user.
static java.lang.String CONSTRUCTORSTRING
           
static java.lang.String DOSETUP
           
static java.lang.String ERROR
           
static java.lang.String ERRORCODE
           
static java.lang.String FAILURE
           
static java.lang.String FAILURECODE
           
static java.lang.String FILTER
           
static java.lang.String METHOD
           
static java.lang.String RUNTEST
           
static java.lang.String SETUP
           
static java.lang.String SUCCESS
           
static java.lang.String SUCCESSCODE
           
static java.lang.String TEARDOWN
           
 
Fields inherited from interface org.apache.jmeter.testelement.TestElement
COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS
 
Constructor Summary
JUnitSampler()
           
 
Method Summary
 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.
 boolean getAppendException()
          If append exception is not set, by default it is set to false.
static java.lang.Object getClassInstance(java.lang.String className, java.lang.String label)
          If the method is not able to create a new instance of the class, it returns null and logs all the exceptions at warning level.
 java.lang.String getClassname()
          Gets the Classname attribute of the JavaConfig object
 java.lang.String getConstructorString()
          get the string passed to the string constructor
 boolean getDoNotSetUpTearDown()
          if the sample shouldn't call setup/teardown, the method returns true.
 java.lang.String getError()
          return the descriptive error for the test
 java.lang.String getErrorCode()
          return the error code for the test method. it should be an unique error code.
 java.lang.String getFailure()
          get the failure message
 java.lang.String getFailureCode()
          The failure code is used by other components
 java.lang.String getFilterString()
          return the comma separated string for the filter
 java.lang.String getMethod()
          Return the name of the method to test
 java.lang.reflect.Method getMethod(java.lang.Object clazz, java.lang.String method)
           
 java.lang.reflect.Method getRunTestMethod(java.lang.Object clazz)
           
 java.lang.String getSuccess()
          get the success message
 java.lang.String getSuccessCode()
          get the success code defined by the user
 SampleResult sample(Entry entry)
          Obtains statistics about the given Entry, and packages the information into a SampleResult.
 void setAppendError(boolean error)
           
 void setAppendException(boolean exc)
           
 void setClassname(java.lang.String classname)
          Sets the Classname attribute of the JavaConfig object
 void setConstructorString(java.lang.String constr)
          Set the string label used to create an instance of the test with the string constructor.
 void setDoNotSetUpTearDown(boolean setup)
          set the setup/teardown option
 void setError(java.lang.String error)
          provide a descriptive error for the test method.
 void setErrorCode(java.lang.String code)
          provide an unique error code for when the test does not pass the assert test.
 void setFailure(java.lang.String fail)
          set the failure message
 void setFailureCode(java.lang.String code)
          Provide some unique code to denote a type of failure
 void setFilterString(java.lang.String text)
          set the filter string in comman separated format
 void setMethod(java.lang.String methodName)
          Method should add the JUnit testXXX method to the list at the end, since the sequence matters.
 void setSuccess(java.lang.String success)
          set the success message
 void setSuccessCode(java.lang.String code)
          set the succes code. the success code should be unique.
 
Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement
addProperty, addTestElement, canRemove, clear, clearTemporary, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jmeter.testelement.TestElement
addTestElement, canRemove, clear, clone, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removeProperty, setComment, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse
 

Field Detail

CLASSNAME

public static final java.lang.String CLASSNAME
Property key representing the classname of the JavaSamplerClient to user.

See Also:
Constant Field Values

CONSTRUCTORSTRING

public static final java.lang.String CONSTRUCTORSTRING
See Also:
Constant Field Values

METHOD

public static final java.lang.String METHOD
See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
See Also:
Constant Field Values

ERRORCODE

public static final java.lang.String ERRORCODE
See Also:
Constant Field Values

FAILURE

public static final java.lang.String FAILURE
See Also:
Constant Field Values

FAILURECODE

public static final java.lang.String FAILURECODE
See Also:
Constant Field Values

SUCCESS

public static final java.lang.String SUCCESS
See Also:
Constant Field Values

SUCCESSCODE

public static final java.lang.String SUCCESSCODE
See Also:
Constant Field Values

FILTER

public static final java.lang.String FILTER
See Also:
Constant Field Values

DOSETUP

public static final java.lang.String DOSETUP
See Also:
Constant Field Values

APPEND_ERROR

public static final java.lang.String APPEND_ERROR
See Also:
Constant Field Values

APPEND_EXCEPTION

public static final java.lang.String APPEND_EXCEPTION
See Also:
Constant Field Values

SETUP

public static final java.lang.String SETUP
See Also:
Constant Field Values

TEARDOWN

public static final java.lang.String TEARDOWN
See Also:
Constant Field Values

RUNTEST

public static final java.lang.String RUNTEST
See Also:
Constant Field Values
Constructor Detail

JUnitSampler

public JUnitSampler()
Method Detail

setClassname

public void setClassname(java.lang.String classname)
Sets the Classname attribute of the JavaConfig object

Parameters:
classname - the new Classname value

getClassname

public java.lang.String getClassname()
Gets the Classname attribute of the JavaConfig object

Returns:
the Classname value

setConstructorString

public void setConstructorString(java.lang.String constr)
Set the string label used to create an instance of the test with the string constructor.

Parameters:
constr -

getConstructorString

public java.lang.String getConstructorString()
get the string passed to the string constructor


getMethod

public java.lang.String getMethod()
Return the name of the method to test


setMethod

public void setMethod(java.lang.String methodName)
Method should add the JUnit testXXX method to the list at the end, since the sequence matters.

Parameters:
methodName -

getSuccess

public java.lang.String getSuccess()
get the success message


setSuccess

public void setSuccess(java.lang.String success)
set the success message

Parameters:
success -

getSuccessCode

public java.lang.String getSuccessCode()
get the success code defined by the user


setSuccessCode

public void setSuccessCode(java.lang.String code)
set the succes code. the success code should be unique.

Parameters:
code -

getFailure

public java.lang.String getFailure()
get the failure message


setFailure

public void setFailure(java.lang.String fail)
set the failure message

Parameters:
fail -

getFailureCode

public java.lang.String getFailureCode()
The failure code is used by other components


setFailureCode

public void setFailureCode(java.lang.String code)
Provide some unique code to denote a type of failure

Parameters:
code -

getError

public java.lang.String getError()
return the descriptive error for the test


setError

public void setError(java.lang.String error)
provide a descriptive error for the test method. For a description of the difference between failure and error, please refer to the following url http://junit.sourceforge.net/doc/faq/faq.htm#tests_9

Parameters:
error -

getErrorCode

public java.lang.String getErrorCode()
return the error code for the test method. it should be an unique error code.


setErrorCode

public void setErrorCode(java.lang.String code)
provide an unique error code for when the test does not pass the assert test.

Parameters:
code -

getFilterString

public java.lang.String getFilterString()
return the comma separated string for the filter


setFilterString

public void setFilterString(java.lang.String text)
set the filter string in comman separated format

Parameters:
text -

getDoNotSetUpTearDown

public boolean getDoNotSetUpTearDown()
if the sample shouldn't call setup/teardown, the method returns true. It's meant for onetimesetup and onetimeteardown.


setDoNotSetUpTearDown

public void setDoNotSetUpTearDown(boolean setup)
set the setup/teardown option

Parameters:
setup -

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


setAppendError

public void setAppendError(boolean error)

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.


setAppendException

public void setAppendException(boolean exc)

sample

public SampleResult sample(Entry entry)
Description copied from interface: Sampler
Obtains statistics about the given Entry, and packages the information into a SampleResult.


getClassInstance

public static java.lang.Object getClassInstance(java.lang.String className,
                                                java.lang.String label)
If the method is not able to create a new instance of the class, it returns null and logs all the exceptions at warning level.


getMethod

public java.lang.reflect.Method getMethod(java.lang.Object clazz,
                                          java.lang.String method)
Parameters:
clazz -
method -
Returns:
the method or null if an error occurred

getRunTestMethod

public java.lang.reflect.Method getRunTestMethod(java.lang.Object clazz)

Apache JMeter

Copyright © 1998-2009 Apache Software Foundation. All Rights Reserved.