How to use JUnit4TestMethod class of org.testng.junit package

Best Testng code snippet using org.testng.junit.JUnit4TestMethod

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.testng.junit;
2
3import java.lang.reflect.Method;
4import org.junit.runner.Description;
5import org.testng.internal.Utils;
6
7/**
8 *
9 * @author lukas
10 */
11public class JUnit4TestMethod extends JUnitTestMethod {
12
13    public JUnit4TestMethod(JUnitTestClass owner, Description desc) {
14        super(owner, desc.getMethodName(), getMethod(desc), desc);
15    }
16
17    @Override
18    public Object[] getInstances() {
19        return new Object[0];
20    }
21
22    private static Method getMethod(Description desc) {
23        Class<?> c = desc.getTestClass();
24        String method = desc.getMethodName();
25        // remove [index] from method name in case of parameterized test
26        int idx = method.indexOf('[');
27        if (idx != -1) {
28            method = method.substring(0, idx);
29        }
30        try {
31            return c.getMethod(method);
32        } catch (Throwable t) {
33            Utils.log("JUnit4TestMethod", 2,
34                    "Method '" + method + "' not found in class '" + c.getName() + "': " + t.getMessage());
35            return null;
36        }
37    }
38}
39
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTestā€™s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on JUnit4TestMethod

    No relevant questions found for this class šŸ˜ž

Most used methods in JUnit4TestMethod

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)