package com.test;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import org.junit.Test;
public class Application
{
public void run(String ClassName) throws Exception
{
Class<?> classType = Class.forName(ClassName);
Object object = classType.newInstance();
Method[] methods = classType.getMethods();
for(int i = 0; i< methods.length;i++)
{
if(methods[i].isAnnotationPresent(Test.class))
{
Type type = methods[i].getReturnType();
Type[] param = methods[i].getGenericParameterTypes();
if(type == void.class && param.length == 0)
{
methods[i].invoke(object,new Object[]{});
}
}
}
return;
}
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import org.junit.Test;
public class Application
{
public void run(String ClassName) throws Exception
{
Class<?> classType = Class.forName(ClassName);
Object object = classType.newInstance();
Method[] methods = classType.getMethods();
for(int i = 0; i< methods.length;i++)
{
if(methods[i].isAnnotationPresent(Test.class))
{
Type type = methods[i].getReturnType();
Type[] param = methods[i].getGenericParameterTypes();
if(type == void.class && param.length == 0)
{
methods[i].invoke(object,new Object[]{});
}
}
}
return;
}
}
package com.test;
import org.junit.Test;
public class MyTest
{
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
System.out.println("zjhans");
Application app = new Application();
app.run("com.test.myTEST");
}
@Test
public void add()
{
System.out.println("This is Test");
}
}