Class JUnitSampler
java.lang.Object
org.apache.jmeter.testelement.AbstractTestElement
org.apache.jmeter.samplers.AbstractSampler
org.apache.jmeter.protocol.java.sampler.JUnitSampler
- All Implemented Interfaces:
- Serializable,- Cloneable,- ConfigMergabilityIndicator,- Searchable,- Sampler,- org.apache.jmeter.testelement.TestElement,- 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:
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.jmeter.testelement.TestElementorg.apache.jmeter.testelement.TestElement.Companion
- 
Field SummaryFields inherited from interface org.apache.jmeter.testelement.TestElementCOMMENTS, Companion, ENABLED, GUI_CLASS, NAME, TEST_CLASS
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanIf 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.booleanIf append exception is not set, by default it is set tofalse.Gets the Classname attribute of the JavaConfig objectbooleanbooleanif the sample shouldn't call setup/teardown, the method returns true.getError()booleanCheck if JUnit4 (annotations) are to be used instead of the JUnit3 style (TestClass and specific method names)Obtains statistics about the given Entry, and packages the information into a SampleResult.voidsetAppendError(boolean error) Set whether to append errors or not.voidsetAppendException(boolean exc) Set whether to append exceptions or not.voidsetClassname(String className) Sets the Classname attribute of the JavaConfig objectvoidsetConstructorString(String constr) Set the string label used to create an instance of the test with the string constructor.voidsetCreateOneInstancePerSample(boolean createOneInstancePerSample) voidsetDoNotSetUpTearDown(boolean setup) set the setup/teardown optionvoidprovide a descriptive error for the test method.voidsetErrorCode(String code) Provide an unique error code for when the test does not pass the assert test.voidsetFailure(String fail) set the failure messagevoidsetFailureCode(String code) Provide some unique code to denote a type of failurevoidsetFilterString(String text) set the filter string in comma separated formatvoidsetJunit4(boolean junit4) Set whether to use JUnit4 style or not.voidMethod should add the JUnit testXXX method to the list at the end, since the sequence matters.voidsetSuccess(String success) set the success messagevoidsetSuccessCode(String code) Set the success code.voidCalled for each thread after all samples have been processed.voidSet up all variables that don't change between samples.Methods inherited from class org.apache.jmeter.samplers.AbstractSamplerappliesMethods inherited from class org.apache.jmeter.testelement.AbstractTestElementaddPropertiesValues, addProperty, addProperty, addTestElement, canRemove, clear, clearTemporary, clearTestElementChildren, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getPropertyOrNull, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traversePropertyMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.jmeter.testelement.TestElementaddTestElement, canRemove, clear, clearTestElementChildren, clone, get, get, get, get, get, get, get, get, get, getComment, getName, getOrCreate, getOrCreate, getOrNull, getOrNull, getOrNull, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getPropertyOrNull, getPropertyOrNull, getProps, getSchema, getString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removed, removeProperty, removeProperty, set, set, set, set, set, set, set, set, set, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse
- 
Constructor Details- 
JUnitSamplerpublic JUnitSampler()
 
- 
- 
Method Details- 
setClassnameSets the Classname attribute of the JavaConfig object- Parameters:
- className- the new Classname value
 
- 
getClassnameGets the Classname attribute of the JavaConfig object- Returns:
- the Classname value
 
- 
setConstructorStringSet the string label used to create an instance of the test with the string constructor.- Parameters:
- constr- the string passed to the constructor
 
- 
getConstructorString- Returns:
- the string passed to the string constructor
 
- 
getMethod- Returns:
- the name of the method to test
 
- 
setMethodMethod should add the JUnit testXXX method to the list at the end, since the sequence matters.- Parameters:
- methodName- name of the method to test
 
- 
getSuccess- Returns:
- the success message
 
- 
setSuccessset the success message- Parameters:
- success- message to be used for success
 
- 
getSuccessCode- Returns:
- the success code defined by the user
 
- 
setSuccessCodeSet the success code. The success code should be unique.- Parameters:
- code- unique success code
 
- 
getFailure- Returns:
- the failure message
 
- 
setFailureset the failure message- Parameters:
- fail- the failure message
 
- 
getFailureCode- Returns:
- The failure code that is used by other components
 
- 
setFailureCodeProvide some unique code to denote a type of failure- Parameters:
- code- unique code to denote the type of failure
 
- 
getError- Returns:
- the descriptive error for the test
 
- 
setErrorprovide a descriptive error for the test method. For a description of the difference between failure and error, please refer to the junit faq- Parameters:
- error- the description of the error
 
- 
getErrorCode- Returns:
- the error code for the test method. It should be an unique error code.
 
- 
setErrorCodeProvide an unique error code for when the test does not pass the assert test.- Parameters:
- code- unique error code
 
- 
getFilterString- Returns:
- the comma separated string for the filter
 
- 
setFilterStringset the filter string in comma separated format- Parameters:
- text- comma separated filter
 
- 
getDoNotSetUpTearDownpublic boolean getDoNotSetUpTearDown()if the sample shouldn't call setup/teardown, the method returns true. It's meant for onetimesetup and onetimeteardown.- Returns:
- flag whether setup/teardown methods should not be called
 
- 
setDoNotSetUpTearDownpublic void setDoNotSetUpTearDown(boolean setup) set the setup/teardown option- Parameters:
- setup- flag whether the setup/teardown methods should not be called
 
- 
getAppendErrorpublic 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- Returns:
- flag whether errors should be appended
 
- 
setAppendErrorpublic void setAppendError(boolean error) Set whether to append errors or not.- Parameters:
- error- the setting to apply
 
- 
getAppendExceptionpublic boolean getAppendException()If append exception is not set, by default it is set tofalse. Users have to explicitly set it totrueto see the exceptions in the result tree.- Returns:
- flag whether exceptions should be appended to the result tree
 
- 
setAppendExceptionpublic void setAppendException(boolean exc) Set whether to append exceptions or not.- Parameters:
- exc- the setting to apply.
 
- 
getJunit4public boolean getJunit4()Check if JUnit4 (annotations) are to be used instead of the JUnit3 style (TestClass and specific method names)- Returns:
- true if JUnit4 (annotations) are to be used. Default is false.
 
- 
setJunit4public void setJunit4(boolean junit4) Set whether to use JUnit4 style or not.- Parameters:
- junit4- true if JUnit4 style is to be used.
 
- 
sampleObtains statistics about the given Entry, and packages the information into a SampleResult.
- 
threadFinishedpublic void threadFinished()Description copied from interface:ThreadListenerCalled for each thread after all samples have been processed. See org.apache.jmeter.threads.JMeterThread#threadFinished(org.apache.jmeter.engine.event.LoopIterationListener)- Specified by:
- threadFinishedin interface- ThreadListener
 
- 
threadStartedpublic void threadStarted()Set up all variables that don't change between samples.- Specified by:
- threadStartedin interface- ThreadListener
 
- 
setCreateOneInstancePerSamplepublic void setCreateOneInstancePerSample(boolean createOneInstancePerSample) - Parameters:
- createOneInstancePerSample- flag whether a new instance for each call should be created
 
- 
getCreateOneInstancePerSamplepublic boolean getCreateOneInstancePerSample()- Returns:
- boolean create New Instance For Each Call
 
 
-