1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); you 5 * may not use this file except in compliance with the License. You may obtain a 6 * copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 package com.android.ide.eclipse.tests; 17 18 19 import com.android.ide.eclipse.adt.AdtPlugin; 20 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 24 /** 25 * Container TestSuite for all eclipse unit tests to be run 26 * 27 * Uses Eclipse OSGI to find and then run all junit.junit.framework.Tests in 28 * this plugin, excluding tests in the FuncTests.FUNC_TEST_PACKAGE package 29 * 30 * Since it uses Eclipse OSGI, it must be run in a Eclipse plugin environment 31 * i.e. from Eclipse workbench, this suite must be run using the 32 * "JUnit Plug-in Test" launch configuration as opposed to as a "JUnit Test" 33 * 34 */ 35 public class UnitTests { 36 private static final String TEST_PACKAGE = "com.android"; 37 suite()38 public static Test suite() { 39 TestSuite suite = new TestSuite(); 40 41 UnitTestCollector collector = new UnitTestCollector(); 42 // since this plugin is a fragment which runs insde adt, gather tests from AdtPlugin 43 collector.addTestCases(suite, AdtPlugin.getDefault(), TEST_PACKAGE); 44 45 return suite; 46 } 47 48 /** 49 * Specialized test collector which will skip adding functional tests 50 */ 51 private static class UnitTestCollector extends EclipseTestCollector { 52 /** 53 * Override parent class to exclude functional tests 54 */ 55 @Override isTestClass(Class<?> testClass)56 protected boolean isTestClass(Class<?> testClass) { 57 return super.isTestClass(testClass) && 58 !testClass.getPackage().getName().startsWith(FuncTests.FUNC_TEST_PACKAGE); 59 } 60 } 61 } 62