junit.framework.TestCase.setName()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中junit.framework.TestCase.setName()方法的一些代码示例,展示了TestCase.setName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TestCase.setName()方法的具体详情如下:
包路径:junit.framework.TestCase
类名称:TestCase
方法名:setName

TestCase.setName介绍

[英]Sets the name of a TestCase
[中]设置测试用例的名称

代码示例

代码示例来源:origin: cbeust/testng

@Override
public void setName(String name) {
 ppp("SETNAME " + name);
 super.setName(name);
}

代码示例来源:origin: junit-team/junit4

/**
 * ...as the moon sets over the early morning Merlin, Oregon
 * mountains, our intrepid adventurers type...
 */
static public Test createTest(Class<?> theClass, String name) {
  Constructor<?> constructor;
  try {
    constructor = getTestConstructor(theClass);
  } catch (NoSuchMethodException e) {
    return warning("Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()");
  }
  Object test;
  try {
    if (constructor.getParameterTypes().length == 0) {
      test = constructor.newInstance(new Object[0]);
      if (test instanceof TestCase) {
        ((TestCase) test).setName(name);
      }
    } else {
      test = constructor.newInstance(new Object[]{name});
    }
  } catch (InstantiationException e) {
    return (warning("Cannot instantiate test case: " + name + " (" + Throwables.getStacktrace(e) + ")"));
  } catch (InvocationTargetException e) {
    return (warning("Exception in constructor: " + name + " (" + Throwables.getStacktrace(e.getTargetException()) + ")"));
  } catch (IllegalAccessException e) {
    return (warning("Cannot access test case: " + name + " (" + Throwables.getStacktrace(e) + ")"));
  }
  return (Test) test;
}

代码示例来源:origin: google/j2objc

/**
 * ...as the moon sets over the early morning Merlin, Oregon
 * mountains, our intrepid adventurers type...
 */
static public Test createTest(Class<?> theClass, String name) {
  Constructor<?> constructor;
  try {
    constructor = getTestConstructor(theClass);
  } catch (NoSuchMethodException e) {
    return warning("Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()");
  }
  Object test;
  try {
    if (constructor.getParameterTypes().length == 0) {
      test = constructor.newInstance(new Object[0]);
      if (test instanceof TestCase) {
        ((TestCase) test).setName(name);
      }
    } else {
      test = constructor.newInstance(new Object[]{name});
    }
  } catch (InstantiationException e) {
    return (warning("Cannot instantiate test case: " + name + " (" + exceptionToString(e) + ")"));
  } catch (InvocationTargetException e) {
    return (warning("Exception in constructor: " + name + " (" + exceptionToString(e.getTargetException()) + ")"));
  } catch (IllegalAccessException e) {
    return (warning("Cannot access test case: " + name + " (" + exceptionToString(e) + ")"));
  }
  return (Test) test;
}

代码示例来源:origin: konsoletyper/teavm

} else {
  runner = new JUnit3Runner(instance);
  ((TestCase) instance).setName(child.getName());

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * ...as the moon sets over the early morning Merlin, Oregon
 * mountains, our intrepid adventurers type...
 */
static public Test createTest(Class<?> theClass, String name) {
  Constructor<?> constructor;
  try {
    constructor = getTestConstructor(theClass);
  } catch (NoSuchMethodException e) {
    return warning("Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()");
  }
  Object test;
  try {
    if (constructor.getParameterTypes().length == 0) {
      test = constructor.newInstance(new Object[0]);
      if (test instanceof TestCase) {
        ((TestCase) test).setName(name);
      }
    } else {
      test = constructor.newInstance(new Object[]{name});
    }
  } catch (InstantiationException e) {
    return (warning("Cannot instantiate test case: " + name + " (" + exceptionToString(e) + ")"));
  } catch (InvocationTargetException e) {
    return (warning("Exception in constructor: " + name + " (" + exceptionToString(e.getTargetException()) + ")"));
  } catch (IllegalAccessException e) {
    return (warning("Cannot access test case: " + name + " (" + exceptionToString(e) + ")"));
  }
  return (Test) test;
}

代码示例来源:origin: io.snappydata/gemfire-junit

@Override
public void setName(String name) {
 super.setName(name);
}

代码示例来源:origin: io.snappydata/gemfire-junit

@Override
public void setName(String name) {
 super.setName(name);
}

代码示例来源:origin: gosu-lang/old-gosu-repo

@Override
public void setName(String name) {
 super.setName(name);
}

代码示例来源:origin: org.seasar.kvasir/kvasir-test

@SuppressWarnings("unchecked")
@Override
public void runBare()
  throws Throwable
{
  TestCase testCase = actualTestClass_.newInstance();
  testCase.setName(getName());
  actualTestClass_.getMethod("runBare0", new Class[0]).invoke(testCase,
    new Object[0]);
}

代码示例来源:origin: blazegraph/database

private static Test createTest(final Class<? extends TestCase> clazz, final String name) {
    try {
      final Constructor<?> cons = TestSuite.getTestConstructor(clazz);
      if (cons.getParameterTypes().length == 1) {
        return (Test) cons.newInstance(name);
      } else {
        final TestCase test = (TestCase) cons.newInstance();
        test.setName(name);
        return test;
      }
    }  catch (final NoSuchMethodException e) {
      throw new RuntimeException("Failed to find constructor");
    } catch (final InstantiationException e) {
      throw new RuntimeException(e);
    } catch (final IllegalAccessException e) {
      throw new RuntimeException(e);
    } catch (final IllegalArgumentException e) {
      throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-repository-compliance-base

@Override
public void setName(String name) {
  super.setName(name);
  String[] fields = name.split(" ", 3);
  term1 = getTerm(fields[0]);
  operator = fields[1];
  term2 = getTerm(fields[2]);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.junit.runtime

private Test createTest(String testName, Class testClass) {
  Class[] classArgs= { String.class };
  Test test;
  Constructor constructor= null;
  try {
    try {
      constructor= testClass.getConstructor(classArgs);
      test= (Test) constructor.newInstance(new Object[] { testName });
    } catch (NoSuchMethodException e) {
      // try the no arg constructor supported in 3.8.1
      constructor= testClass.getConstructor(new Class[0]);
      test= (Test) constructor.newInstance(new Object[0]);
      if (test instanceof TestCase)
        ((TestCase) test).setName(testName);
    }
    if (test != null)
      return test;
  } catch (InstantiationException e) {
  } catch (IllegalAccessException e) {
  } catch (InvocationTargetException e) {
  } catch (NoSuchMethodException e) {
  } catch (ClassCastException e) {
  }
  return error(testName, "Could not create test \'" + testName + "\' "); //$NON-NLS-1$ //$NON-NLS-2$
}

代码示例来源:origin: gosu-lang/old-gosu-repo

public static <T extends TestCase> Test createTestSuite(Class<T> clazz, Iterable<String> methodNames) {
 try {
  Constructor<T> constructor = getConstructor(clazz);
  junit.framework.TestSuite newSuite = new junit.framework.TestSuite();
  for (String name : methodNames) {
   TestCase test;
   if (constructor.getParameterTypes().length == 0) {
    test = constructor.newInstance();
    test.setName(name);
   } else {
    test = constructor.newInstance(name);
   }
   newSuite.addTest(test);
  }
  return newSuite;
 } catch (InstantiationException e) {
  throw new RuntimeException("Cannot instantiate test class " + clazz.getName(), e);
 } catch (IllegalAccessException e) {
  throw new RuntimeException(clazz.getName() + " constructor is not accessible", e);
 } catch (InvocationTargetException e) {
  throw new RuntimeException(clazz.getName() + "(String name) constructor threw an exception", e);
 }
}

代码示例来源:origin: com.mockrunner/mockrunner-jdk1.3-j2ee1.3

private Test createNewTestInstanceBasedOn(TestCase test)
{
  TestCase newTest = null;
  try
  {    
    Constructor constructor = getTestConstructor(test.getClass());
    if (constructor.getParameterTypes().length == 0) 
    {
      newTest = (TestCase)constructor.newInstance(new Object[0]);
      newTest.setName(test.getName());
              
    } 
    else 
    {
      newTest = (TestCase)constructor.newInstance(new Object[]{test.getName()});
    }
  }
  catch(Exception exc)
  {
    log.error(exc.getMessage(), exc);
  }
  return newTest;
}

代码示例来源:origin: com.mockrunner/mockrunner-jdk1.4-j2ee1.3

private Test createNewTestInstanceBasedOn(TestCase test)
{
  TestCase newTest = null;
  try
  {    
    Constructor constructor = getTestConstructor(test.getClass());
    if (constructor.getParameterTypes().length == 0) 
    {
      newTest = (TestCase)constructor.newInstance(new Object[0]);
      newTest.setName(test.getName());
              
    } 
    else 
    {
      newTest = (TestCase)constructor.newInstance(new Object[]{test.getName()});
    }
  }
  catch(Exception exc)
  {
    log.error(exc.getMessage(), exc);
  }
  return newTest;
}

代码示例来源:origin: blazegraph/database

private static Test createTest(final Class<? extends TestCase> clazz, final String name) {
    try {
      final Constructor<?> cons = TestSuite.getTestConstructor(clazz);
      if (cons.getParameterTypes().length == 1) {
        return (Test) cons.newInstance(name);
      } else {
        final TestCase test = (TestCase) cons.newInstance();
        test.setName(name);
        return test;
      }
    }  catch (final NoSuchMethodException e) {
      throw new RuntimeException("Failed to find constructor");
    } catch (final InstantiationException e) {
      throw new RuntimeException(e);
    } catch (final IllegalAccessException e) {
      throw new RuntimeException(e);
    } catch (final IllegalArgumentException e) {
      throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: org.apache.jena/jena-core

static private void addTests(TestSuite s, String dir, String base, String file) {
  
  TestCase tc = new StAX2ModelTest(dir, base, file);
  tc.setName("StAX " + tc.getName());
  s.addTest(tc);
}
final String base;

代码示例来源:origin: apache/jena

static private void addTests(TestSuite s, String dir, String base, String file){
  TestCase tc = new SAX2RDFTest(dir,base,file);
  tc.setName("SAX "+tc.getName());
  s.addTest(tc);
  
  tc = new DOM2RDFTest(dir,base,file);
  
  tc.setName("DOM "+tc.getName());
  s.addTest(tc);
}

代码示例来源:origin: apache/jena

static private void addTests(TestSuite s, String dir, String base, String file) {
  
  TestCase tc = new StAX2ModelTest(dir, base, file);
  tc.setName("StAX " + tc.getName());
  s.addTest(tc);
}
final String base;

代码示例来源:origin: org.apache.jena/jena-core

static private void addTests(TestSuite s, String dir, String base, String file){
  TestCase tc = new SAX2RDFTest(dir,base,file);
  tc.setName("SAX "+tc.getName());
  s.addTest(tc);
  
  tc = new DOM2RDFTest(dir,base,file);
  
  tc.setName("DOM "+tc.getName());
  s.addTest(tc);
}

相关文章