org.apache.jmeter.protocol.java.sampler

Class JUnitSampler

Implemented Interfaces:
Cloneable, Sampler, Serializable, 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.

Field Summary

static String
APPEND_ERROR
static String
APPEND_EXCEPTION
static String
CLASSNAME
Property key representing the classname of the JavaSamplerClient to user.
static String
CONSTRUCTORSTRING
static String
DOSETUP
static String
ERROR
static String
ERRORCODE
static String
FAILURE
static String
FAILURECODE
static String
FILTER
static String
METHOD
static String
RUNTEST
static String
SETUP
static String
SUCCESS
static String
SUCCESSCODE
static 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 Object
getClassInstance(String className, 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.
String
getClassname()
Gets the Classname attribute of the JavaConfig object
String
getConstructorString()
get the string passed to the string constructor
boolean
getDoNotSetUpTearDown()
if the sample shouldn't call setup/teardown, the method returns true.
String
getError()
return the descriptive error for the test
String
getErrorCode()
return the error code for the test method. it should be an unique error code.
String
getFailure()
get the failure message
String
getFailureCode()
The failure code is used by other components
String
getFilterString()
return the comma separated string for the filter
String
getMethod()
Return the name of the method to test
Method
getMethod(Object clazz, String method)
Method
getRunTestMethod(Object clazz)
String
getSuccess()
get the success message
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(String classname)
Sets the Classname attribute of the JavaConfig object
void
setConstructorString(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(String error)
provide a descriptive error for the test method.
void
setErrorCode(String code)
provide an unique error code for when the test does not pass the assert test.
void
setFailure(String fail)
set the failure message
void
setFailureCode(String code)
Provide some unique code to denote a type of failure
void
setFilterString(String text)
set the filter string in comman separated format
void
setMethod(String methodName)
Method should add the JUnit testXXX method to the list at the end, since the sequence matters.
void
setSuccess(String success)
set the success message
void
setSuccessCode(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

Field Details

APPEND_ERROR

public static final String APPEND_ERROR

APPEND_EXCEPTION

public static final String APPEND_EXCEPTION

CLASSNAME

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

CONSTRUCTORSTRING

public static final String CONSTRUCTORSTRING

DOSETUP

public static final String DOSETUP

ERROR

public static final String ERROR

ERRORCODE

public static final String ERRORCODE

FAILURE

public static final String FAILURE

FAILURECODE

public static final String FAILURECODE

FILTER

public static final String FILTER

METHOD

public static final String METHOD

RUNTEST

public static final String RUNTEST

SETUP

public static final String SETUP

SUCCESS

public static final String SUCCESS

SUCCESSCODE

public static final String SUCCESSCODE

TEARDOWN

public static final String TEARDOWN

Constructor Details

JUnitSampler

public JUnitSampler()

Method Details

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

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.

getClassInstance

public static Object getClassInstance(String className,
                                      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.

getClassname

public String getClassname()
Gets the Classname attribute of the JavaConfig object
Returns:
the Classname value

getConstructorString

public String getConstructorString()
get the string passed to the string constructor

getDoNotSetUpTearDown

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

getError

public String getError()
return the descriptive error for the test

getErrorCode

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

getFailure

public String getFailure()
get the failure message

getFailureCode

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

getFilterString

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

getMethod

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

getMethod

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

getRunTestMethod

public Method getRunTestMethod(Object clazz)

getSuccess

public String getSuccess()
get the success message

getSuccessCode

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

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

setAppendError

public void setAppendError(boolean error)

setAppendException

public void setAppendException(boolean exc)

setClassname

public void setClassname(String classname)
Sets the Classname attribute of the JavaConfig object
Parameters:
classname - the new Classname value

setConstructorString

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

setDoNotSetUpTearDown

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

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 following url http://junit.sourceforge.net/doc/faq/faq.htm#tests_9
Parameters:
error -

setErrorCode

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

setFailure

public void setFailure(String fail)
set the failure message
Parameters:
fail -

setFailureCode

public void setFailureCode(String code)
Provide some unique code to denote a type of failure
Parameters:
code -

setFilterString

public void setFilterString(String text)
set the filter string in comman separated format
Parameters:
text -

setMethod

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

setSuccess

public void setSuccess(String success)
set the success message
Parameters:
success -

setSuccessCode

public void setSuccessCode(String code)
set the succes code. the success code should be unique.
Parameters:
code -

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