use of junit.framework.TestCase in project android_frameworks_base by ParanoidAndroid.
the class AndroidTestRunnerTest method testRunSingleTestMethod.
public void testRunSingleTestMethod() throws Exception {
String testMethodName = "testTwo";
mAndroidTestRunner.setTestClassName(TwoTestTestCase.class.getName(), testMethodName);
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
List<String> testNames = Lists.newArrayList();
for (TestCase testCase : testCases) {
testNames.add(testCase.getName());
}
assertEquals(Arrays.asList(testMethodName), testNames);
}
use of junit.framework.TestCase in project android_frameworks_base by ParanoidAndroid.
the class TestCaseUtilTest method testGetTestCaseNamesForTestCaseWithSuiteMethod.
public void testGetTestCaseNamesForTestCaseWithSuiteMethod() throws Exception {
TestCase testCase = new OneTestTestCaseWithSuite();
List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testCase, false);
assertEquals(1, testCaseNames.size());
assertTrue(testCaseNames.get(0).endsWith("testOne"));
}
use of junit.framework.TestCase in project powermock by powermock.
the class PowerMockJUnit4MethodValidator method validateTestMethods.
/**
* This is a rip-off of the
* {@link MethodValidator#validateInstanceMethods()} with the exception that
* this method also searches for test methods if the class extends
* {@link TestCase} and has methods that starts with test which are not
* annotated.
*/
@SuppressWarnings("unchecked")
private void validateTestMethods(Class<? extends Annotation> annotation, boolean isStatic) {
TestClass testClass = Whitebox.getInternalState(this, TEST_CLASS_FIELD, MethodValidator.class);
Class<?> classUnderTest = Whitebox.getInternalState(testClass, CLASS_UNDER_TEST_FIELD);
final List<Method> methods;
if (TestCase.class.equals(classUnderTest.getSuperclass()) && !isStatic) {
methods = getTestMethodsWithNoAnnotation(classUnderTest);
} else {
methods = testClass.getAnnotatedMethods(annotation);
}
List<Throwable> fErrors = Whitebox.getInternalState(this, ERRORS_FIELD, MethodValidator.class);
for (Method each : methods) {
if (Modifier.isStatic(each.getModifiers()) != isStatic) {
String state = isStatic ? "should" : "should not";
fErrors.add(new Exception("Method " + each.getName() + "() " + state + " be static"));
}
if (!Modifier.isPublic(each.getDeclaringClass().getModifiers()))
fErrors.add(new Exception("Class " + each.getDeclaringClass().getName() + " should be public"));
if (!Modifier.isPublic(each.getModifiers()))
fErrors.add(new Exception("Method " + each.getName() + " should be public"));
if (each.getReturnType() != Void.TYPE)
fErrors.add(new Exception("Method " + each.getName() + " should be void"));
if (each.getParameterTypes().length != 0)
fErrors.add(new Exception("Method " + each.getName() + " should have no parameters"));
}
}
use of junit.framework.TestCase in project robovm by robovm.
the class RoboVMAllTests method hasTests.
private static boolean hasTests(Test test) {
if (test == null) {
return false;
}
if (test.countTestCases() > 1) {
return true;
}
if (!(test instanceof TestSuite)) {
return true;
}
TestSuite suite = (TestSuite) test;
if (!(suite.testAt(0) instanceof TestCase)) {
return true;
}
TestCase singleTest = (TestCase) suite.testAt(0);
return !singleTest.getName().equals("warning");
}
use of junit.framework.TestCase in project platform_frameworks_base by android.
the class TestCaseCollector method addSingleTestMethod.
protected void addSingleTestMethod(Class<?> clazz, String method) {
if (!(mFilter.accept(clazz))) {
throw new RuntimeException("Test class must be derived from UiAutomatorTestCase");
}
try {
TestCase testCase = (TestCase) clazz.newInstance();
testCase.setName(method);
mTestCases.add(testCase);
} catch (InstantiationException e) {
mTestCases.add(error(clazz, "InstantiationException: could not instantiate " + "test class. Class: " + clazz.getName()));
} catch (IllegalAccessException e) {
mTestCases.add(error(clazz, "IllegalAccessException: could not instantiate " + "test class. Class: " + clazz.getName()));
}
}
Aggregations