1 /* 2 * $Id$ 3 * 4 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Oracle designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Oracle in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24 * or visit www.oracle.com if you need additional information or have any 25 * questions. 26 */ 27 package com.sun.javatest.junit; 28 29 import com.sun.javatest.TestRunner; 30 import com.sun.javatest.TestSuite; 31 import java.io.File; 32 import java.util.Map; 33 import java.net.URLClassLoader; 34 import java.net.URL; 35 36 /** 37 * Basic implementation of a test suite for JUnit tests. 38 */ 39 public class JUnitTestSuite extends TestSuite { 40 public JUnitTestSuite(File root, Map<String, String> props, ClassLoader loader) throws TestSuite.Fault { 41 super(root, props, loader); 42 try { 43 if (getTestsDir() != null) 44 loader = new URLClassLoader(new URL[] {getTestsDir().toURI().toURL()}, loader); 45 else loader = ClassLoader.getSystemClassLoader(); 46 } catch(Exception e) { 47 } 48 cl = loader; 49 } 50 51 /** 52 * Implementation here creates a JUnitTestRunner. 53 * Override if you wish to supply your own test runner. 54 */ 55 public TestRunner createTestRunner() { 56 // will need to add options to test suite to be passed to runner 57 // for ex. - to run setup/teardown, etc... 58 try { 59 Class<?> c = loadClass("com.sun.javatest.junit.JUnitTestRunner"); 60 JUnitTestRunner tr = (JUnitTestRunner)(c.newInstance()); 61 tr.setClassLoader(getClassLoader()); 62 return tr; 63 } 64 catch (TestSuite.Fault f) { 65 f.printStackTrace(); 66 // this will probably be ok, should log and error though 67 return new JUnitTestRunner(); 68 } 69 catch (InstantiationException e) { 70 e.printStackTrace(); 71 return new JUnitTestRunner(); 72 } 73 catch (IllegalAccessException e) { 74 e.printStackTrace(); 75 return new JUnitTestRunner(); 76 } 77 } 78 79 private ClassLoader cl; 80 }