In this post I will show you how to integrate and execute Junit test with Jmeter .
Junit test:
Here I have created two Junit test:
1. JunitFirstTest.java:
Junit test:
Here I have created two Junit test:
1. JunitFirstTest.java:
package com.test;
import org.junit.*;
public class JunitFirstTest {
@BeforeClass
public static void beforeClassAnnotation() {
System.out.println("@BeforeClass
- for junit class 1");
}
@AfterClass
public static void afterClassAnnotation() {
System.out.println("@AfterClass
- for junit class 1");
}
@Test
public void testAnnotation() {
System.out.println("@Test - first class test method");
}
}
package
com.test;
import
org.junit.*;
public class
JunitSecondTest {
@BeforeClass
public static void beforeClassAnnotation()
{
System.out.println("@BeforeClass
- for junit class 2");
}
@AfterClass
public static void afterClassAnnotation()
{
System.out.println("@AfterClass
- for junit class 2");
}
@Test
public void testMethod2() {
System.out.println("@Test - Second
class test method");
}
}
Note: add suffix “Test” in class name of your junit test
Creating Jar file:
Compile your all junit test and put all compiled (.class) file and .java file into package what your junit test have. As above junit test have package “com.test” so we need to create “com\test” folder and put all junit .java and .class file in this folder. See as in below screen:
Open command prompt and goto root folder as I “E:\Junit-Test”. Run below command to create jar file for the same.
jar cvf
Jmeter-Junit.jar *.*
You should see “Jmeter-Junit.jar” file is created.
Integration with Jmeter:
Put this jar file under your Jmeter “lib>>junit” folder.
Go to bin folder and launch Jmeter.
Create Thread group in Jmeter, right click on “Thread Group” and create Junit test request.
Click on check box “Search for Junit 4 annotation (Instead of Junit 3) if your test is in Junit 4. Your Junit test classes listed as below screen:
Now you are ready to create and execute Jmeter test of your Junit scripts.
I followed all the steps you have mentioned and successfully created and copied jar file to /lib/junit of JMeter. But my classes do not appear on the list in JMeter. Can you please suggest what might be the reason for that?
ReplyDeleteI needed to restart JMeter for seeing those classes. Works now.
ReplyDeleteThanks Pratikshya
ReplyDeleteI am followed same steps but still not reflecting the class name
ReplyDeleteplease update ur jmeter 3 and add slenium webdriver , than try
ReplyDeleteTried adding selenium webdriver and jmeter 3.1 still i didnt find the java class in the jmeter
ReplyDeleteI'm having the same problem. I couldn't see the class name reflected in JUnit any advice?
Deletei ran the junit class but not able to see results in view listner tree
ReplyDeleteFollowed similar steps --> After running the JUnit Request,Status is Pass;
ReplyDeleteRequest is Package.ClassName.Method Name . but there is no response data. Bytes, Sent Bytes, Latency is Zero
Hi even I’m having the same problem. Couldn’t find the classname when I use JUnit request
ReplyDelete