All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.junit.JUnit4TestMethod Maven / Gradle / Ivy

There is a newer version: 7.10.1
Show newest version
package org.testng.junit;

import java.lang.reflect.Method;
import org.junit.runner.Description;
import org.testng.internal.Utils;

/**
 *
 * @author lukas
 */
public class JUnit4TestMethod extends JUnitTestMethod {

    public JUnit4TestMethod(JUnitTestClass owner, Description desc) {
        super(owner, desc.getMethodName(), getMethod(desc), desc);
    }

    @Override
    public Object[] getInstances() {
        return new Object[0];
    }

    private static Method getMethod(Description desc) {
        Class c = desc.getTestClass();
        String method = desc.getMethodName();
        // remove [index] from method name in case of parameterized test
        int idx = method.indexOf('[');
        if (idx != -1) {
            method = method.substring(0, idx);
        }
        try {
            return c.getMethod(method);
        } catch (Throwable t) {
            Utils.log("JUnit4TestMethod", 2,
                    "Method '" + method + "' not found in class '" + c.getName() + "': " + t.getMessage());
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy