You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestHelper.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*******************************************************************************
  2. * Copyright (c) Jonas Bonér, Alexandre Vasseur
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *******************************************************************************/
  8. package ataspectj;
  9. import junit.textui.TestRunner;
  10. import junit.framework.TestResult;
  11. import java.util.Enumeration;
  12. /**
  13. * Helper to run a test as a main class, but still throw exception and not just print on stderr
  14. * upon test failure.
  15. * <p/>
  16. * This is required for Ajc test case that are also designed to work with LTW.
  17. *
  18. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  19. */
  20. public class TestHelper {
  21. public static void runAndThrowOnFailure(junit.framework.Test test) {
  22. TestRunner r = new TestRunner();
  23. TestResult rr = r.doRun(test);
  24. if (!rr.wasSuccessful()) {
  25. StringBuffer sb = new StringBuffer("\n");
  26. Enumeration e = rr.failures();
  27. while (e.hasMoreElements()) {
  28. sb.append("Failure: ");
  29. sb.append(e.nextElement());
  30. sb.append("\n");
  31. }
  32. e = rr.errors();
  33. while (e.hasMoreElements()) {
  34. sb.append("Error: ");
  35. sb.append(e.nextElement());
  36. sb.append("\n");
  37. }
  38. throw new RuntimeException(sb.toString());
  39. }
  40. }
  41. }