FileDocCategorySizeDatePackage
InstrumentationResultParserTest.javaAPI DocAndroid 1.5 API8942Wed May 06 22:41:08 BST 2009com.android.ddmlib.testrunner

InstrumentationResultParserTest

public class InstrumentationResultParserTest extends TestCase
Tests InstrumentationResultParser.

Fields Summary
private InstrumentationResultParser
mParser
private VerifyingTestResult
mTestResult
private static final String
CLASS_NAME
private static final String
TEST_NAME
private static final String
STACK_TRACE
Constructors Summary
public InstrumentationResultParserTest(String name)

param
name - test name


              
       
        super(name);
    
Methods Summary
private voidaddCommonStatus(java.lang.StringBuilder output)
Adds common status results to the provided output.

        addStatusKey(output, "stream", "\r\n" + CLASS_NAME);
        addStatusKey(output, "test", TEST_NAME);
        addStatusKey(output, "class", CLASS_NAME);
        addStatusKey(output, "current", "1");
        addStatusKey(output, "numtests", "1");
        addStatusKey(output, "id", "InstrumentationTestRunner");
    
private voidaddFailureCode(java.lang.StringBuilder outputBuilder)

        addStatusCode(outputBuilder, "-2");
    
private voidaddLineBreak(java.lang.StringBuilder outputBuilder)
Append line break characters to output

        outputBuilder.append("\r\n");
    
private voidaddStackTrace(java.lang.StringBuilder output)
Adds a stack trace status bundle to output.

        addStatusKey(output, "stack", STACK_TRACE);

    
private voidaddStartCode(java.lang.StringBuilder outputBuilder)

        addStatusCode(outputBuilder, "1");
    
private voidaddStatusCode(java.lang.StringBuilder outputBuilder, java.lang.String value)

        outputBuilder.append("INSTRUMENTATION_STATUS_CODE: ");
        outputBuilder.append(value);
        addLineBreak(outputBuilder);
    
private voidaddStatusKey(java.lang.StringBuilder outputBuilder, java.lang.String key, java.lang.String value)
Helper method to add a status key-value bundle.

        outputBuilder.append("INSTRUMENTATION_STATUS: ");
        outputBuilder.append(key);
        outputBuilder.append('=");
        outputBuilder.append(value);
        addLineBreak(outputBuilder);
    
private voidaddSuccessCode(java.lang.StringBuilder outputBuilder)

        addStatusCode(outputBuilder, "0");
    
private voidassertCommonAttributes()

        assertEquals(CLASS_NAME, mTestResult.mSuiteName);
        assertEquals(1, mTestResult.mTestCount);
        assertEquals(TEST_NAME, mTestResult.mTestName);
    
private java.lang.StringBuilderbuildCommonResult()
Builds a common test result using TEST_NAME and TEST_CLASS.

        StringBuilder output = new StringBuilder();
        // add test start bundle
        addCommonStatus(output);
        addStatusCode(output, "1");
        // add end test bundle, without status
        addCommonStatus(output);
        return output;
    
private voidinjectTestString(java.lang.String result)
inject a test string into the result parser.

param
result

        byte[] data = result.getBytes();
        mParser.addOutput(data, 0, data.length);
        mParser.flush();
    
protected voidsetUp()

see
junit.framework.TestCase#setUp()

        super.setUp();
        mTestResult = new VerifyingTestResult();
        mParser = new InstrumentationResultParser(mTestResult);
    
public voidtestRunFailed()
Test basic parsing of a test run failure.

        StringBuilder output = new StringBuilder();        
        final String errorMessage = "Unable to find instrumentation info";
        addStatusKey(output, "Error", errorMessage);
        addStatusCode(output, "-1");
        output.append("INSTRUMENTATION_FAILED: com.dummy/android.test.InstrumentationTestRunner");
        addLineBreak(output);
        
        injectTestString(output.toString());
        
        assertEquals(errorMessage, mTestResult.mRunFailedMessage);
    
public voidtestRunFailedResult()
Test parsing of a test run failure, where an instrumentation component failed to load Parsing input takes the from of INSTRUMENTATION_RESULT: fff

        StringBuilder output = new StringBuilder();        
        final String errorMessage = "Unable to instantiate instrumentation";
        output.append("INSTRUMENTATION_RESULT: shortMsg=");
        output.append(errorMessage);
        addLineBreak(output);
        output.append("INSTRUMENTATION_CODE: 0");
        addLineBreak(output);
        
        injectTestString(output.toString());
        
        assertEquals(errorMessage, mTestResult.mRunFailedMessage);
    
public voidtestTestFailed()
Test basic parsing of failed test case.

        StringBuilder output = buildCommonResult();
        addStartCode(output);
        addCommonStatus(output);
        addStackTrace(output);
        addFailureCode(output);

        injectTestString(output.toString());
        assertCommonAttributes();

        assertEquals(1, mTestResult.mNumTestsRun);
        assertEquals(ITestRunListener.TestFailure.FAILURE, mTestResult.mTestStatus);
        assertEquals(STACK_TRACE, mTestResult.mTrace);
    
public voidtestTestStarted()
Tests that the test run started and test start events is sent on first bundle received.

        StringBuilder output = buildCommonResult();
        addStartCode(output);

        injectTestString(output.toString());
        assertCommonAttributes();
        assertEquals(0, mTestResult.mNumTestsRun);
    
public voidtestTestSuccess()
Tests that a single successful test execution.

        StringBuilder output = buildCommonResult();
        addStartCode(output);
        addCommonStatus(output);
        addSuccessCode(output);

        injectTestString(output.toString());
        assertCommonAttributes();
        assertEquals(1, mTestResult.mNumTestsRun);
        assertEquals(null, mTestResult.mTestStatus);
    
public voidtestTimeParsing()
Test basic parsing and conversion of time from output.

        final String timeString = "Time: 4.9";
        injectTestString(timeString);
        assertEquals(4900, mTestResult.mTestTime);