The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | package android.test; |
| 2 | |
| 3 | import java.io.PrintStream; |
| 4 | |
| 5 | import android.os.Bundle; |
| 6 | |
| 7 | import junit.framework.AssertionFailedError; |
| 8 | import junit.framework.Test; |
| 9 | import junit.framework.TestCase; |
| 10 | import junit.runner.BaseTestRunner; |
| 11 | import junit.textui.ResultPrinter; |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * Subclass of ResultPrinter that adds test case results to a bundle. |
| 16 | * |
| 17 | * {@hide} - This class is deprecated, and will be going away. Please don't use it. |
| 18 | */ |
| 19 | public class BundlePrinter extends ResultPrinter { |
| 20 | |
| 21 | private Bundle mResults; |
| 22 | private boolean mFailure; |
| 23 | private boolean mError; |
| 24 | |
| 25 | public BundlePrinter(PrintStream writer, Bundle result) { |
| 26 | super(writer); |
| 27 | mResults = result; |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public void addError(Test test, Throwable t) { |
| 32 | mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t)); |
| 33 | mFailure = true; |
| 34 | super.addError(test, t); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void addFailure(Test test, AssertionFailedError t) { |
| 39 | mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t)); |
| 40 | mError = true; |
| 41 | super.addFailure(test, t); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void endTest(Test test) { |
| 46 | if (!mFailure && !mError) { |
| 47 | mResults.putString(getComboName(test), "passed"); |
| 48 | } |
| 49 | super.endTest(test); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void startTest(Test test) { |
| 54 | mFailure = false; |
| 55 | mError = false; |
| 56 | super.startTest(test); |
| 57 | } |
| 58 | |
| 59 | private String getComboName(Test test) { |
| 60 | return test.getClass().getName() + ":" + ((TestCase) test).getName(); |
| 61 | } |
| 62 | |
| 63 | } |