nagkumar commented on issue #5957:
URL: https://github.com/apache/jmeter/issues/5957#issuecomment-1584485237

   ```
   package com.tejasoft.tests.ju.ju5.ut.perf.jmeter.ext;
   
   import org.apache.jmeter.samplers.AbstractSampler;
   import org.apache.jmeter.samplers.Entry;
   import org.apache.jmeter.samplers.SampleResult;
   import org.junit.jupiter.api.TestInstance;
   import org.junit.platform.launcher.Launcher;
   import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
   import org.junit.platform.launcher.core.LauncherFactory;
   import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
   import org.junit.platform.launcher.listeners.TestExecutionSummary;
   import org.slf4j.Logger;
   import org.slf4j.LoggerFactory;
   
   import java.io.PrintWriter;
   import java.io.Serial;
   import java.lang.annotation.Annotation;
   import java.lang.reflect.Method;
   
   import static 
org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
   
   @TestInstance(TestInstance.Lifecycle.PER_CLASS)
   public final class JUnit5Sampler extends AbstractSampler implements 
JUnit5SamplerAttributes
   {
       private static final Logger log = 
LoggerFactory.getLogger(JUnit5Sampler.class);
   
       @Serial
       private static final long serialVersionUID = 240L;
   
       private static final boolean CREATE_INSTANCE_PER_SAMPLE_DEFAULT = false;
   
       public JUnit5Sampler()
       {
        super();
       }
   
       public final String getJUnit5TestClass()
       {
        return getPropertyAsString(JUNIT5_TEST_CLASS);
       }
   
       public final void setJUnit5TestClass(final String aJUnit5TestClass)
       {
        setProperty(JUNIT5_TEST_CLASS, aJUnit5TestClass);
       }
   
       public String getConstructorString()
       {
        return getPropertyAsString(CONSTRUCTORSTRING);
       }
   
       public void setConstructorString(String constructorString)
       {
        setProperty(CONSTRUCTORSTRING, constructorString);
       }
   
       public String getMethod()
       {
        return getPropertyAsString(METHOD);
       }
   
       public void setMethod(String method)
       {
        setProperty(METHOD, method);
       }
   
       public String getSuccess()
       {
        return getPropertyAsString(SUCCESS);
       }
   
       public void setSuccess(String success)
       {
        setProperty(SUCCESS, success);
       }
   
       public String getFailure()
       {
        return getPropertyAsString(FAILURE);
       }
   
       public void setFailure(String failure)
       {
        setProperty(FAILURE, failure);
       }
   
       public String getError()
       {
        return getPropertyAsString(ERROR);
       }
   
       public void setError(String error)
       {
        setProperty(ERROR, error);
       }
   
       public String getFilter()
       {
        return getPropertyAsString(FILTER);
       }
   
       public void setFilter(String filter)
       {
        setProperty(FILTER, filter);
       }
   
       public boolean getAppendError()
       {
        return getPropertyAsBoolean(APPEND_ERROR);
       }
   
       public void setAppendError(boolean append)
       {
        setProperty(APPEND_ERROR, append);
       }
   
       public boolean getAppendException()
       {
        return getPropertyAsBoolean(APPEND_EXCEPTION);
       }
   
       public void setAppendException(boolean append)
       {
        setProperty(APPEND_EXCEPTION, append);
       }
   
       public boolean getCreateInstancePerSample()
       {
        return getPropertyAsBoolean(CREATE_INSTANCE_PER_SAMPLE, 
CREATE_INSTANCE_PER_SAMPLE_DEFAULT);
       }
   
       public void setCreateInstancePerSample(boolean createInstance)
       {
        setProperty(CREATE_INSTANCE_PER_SAMPLE, createInstance);
       }
   
       public String toString()
       {
        return getClass().getSimpleName() + " " + getName() + "(" + 
getJUnit5TestClass() + "." + getMethod() + ")";
       }
   
       public String getErrorCode()
       {
        return getPropertyAsString(ERRORCODE);
       }
   
       public String getSuccessCode()
       {
        return getPropertyAsString(SUCCESSCODE);
       }
   
       public String getFailureCode()
       {
        return getPropertyAsString(FAILURECODE);
       }
   
       private Method getMethodWithAnnotation(Object testObject, Class<? 
extends Annotation> annotation)
       {
        Class<?> clazz = testObject.getClass();
        for (Method method : clazz.getMethods())
        {
            if (method.isAnnotationPresent(annotation))
            {
                return method;
            }
        }
        return null;
       }
   
       @Override
       public SampleResult sample(final Entry aEntry)
       {
        final SampleResult lSampleResult = new SampleResult();
        lSampleResult.sampleStart();
   
        try
        {
            final TestExecutionSummary lSummary = runSuiteClass().getSummary();
   
            if (lSummary.getTestsFailedCount() == 0)
            {
                lSampleResult.setSuccessful(true);
            }
            else
            {
                setFailedResponse(lSampleResult, "Some tests failed.");
            }
        }
        catch (final Exception aException)
        {
            setFailedResponse(lSampleResult, "Exception occurred: " + 
aException.getMessage());
        }
   
        lSampleResult.sampleEnd();
        return lSampleResult;
       }
   
       private final SummaryGeneratingListener runSuiteClass()
       {
        LauncherDiscoveryRequestBuilder requestBuilder = 
LauncherDiscoveryRequestBuilder.request();
        requestBuilder.selectors(selectClass(getJUnit5TestClass()));
   
        Launcher launcher = LauncherFactory.create();
        SummaryGeneratingListener listener = new SummaryGeneratingListener();
        launcher.registerTestExecutionListeners(listener);
        launcher.execute(requestBuilder.build());
        listener.getSummary().printTo(new PrintWriter(System.out));
        return listener;
       }
   
       private static final void setFailedResponse(final SampleResult 
aSampleResult, final String aFailMessage)
       {
        aSampleResult.setSuccessful(false);
        aSampleResult.setResponseMessage(aFailMessage);
        aSampleResult.setResponseCode("500");
       }
   }
   
   ```
   
   and 
   
   ```
   package com.tejasoft.tests.ju.ju5.ut.perf.jmeter.ext;
   
   public interface JUnit5SamplerAttributes
   {
       String JUNIT_5_SAMPLER_PROP_PREFIX = "junit5Sampler.";
       String JUNIT5_TEST_CLASS = JUNIT_5_SAMPLER_PROP_PREFIX + "classname";
       String METHOD = JUNIT_5_SAMPLER_PROP_PREFIX + "method";
   
       String CONSTRUCTORSTRING = JUNIT_5_SAMPLER_PROP_PREFIX + 
"constructorstring";
       String ERROR = JUNIT_5_SAMPLER_PROP_PREFIX + "error";
       String ERRORCODE = JUNIT_5_SAMPLER_PROP_PREFIX + "error.code";
       String FAILURE = JUNIT_5_SAMPLER_PROP_PREFIX + "failure";
       String FAILURECODE = JUNIT_5_SAMPLER_PROP_PREFIX + "failure.code";
       String SUCCESS = JUNIT_5_SAMPLER_PROP_PREFIX + "success";
       String SUCCESSCODE = JUNIT_5_SAMPLER_PROP_PREFIX + "success.code";
       String FILTER = JUNIT_5_SAMPLER_PROP_PREFIX + "pkg.filter";
       String APPEND_ERROR = JUNIT_5_SAMPLER_PROP_PREFIX + "append.error";
       String APPEND_EXCEPTION = JUNIT_5_SAMPLER_PROP_PREFIX + 
"append.exception";
       String CREATE_INSTANCE_PER_SAMPLE = JUNIT_5_SAMPLER_PROP_PREFIX + 
"createinstancepersample";
   }
   
   ```
   
   this is the code.. I am using..


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@jmeter.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to