Chromium Code Reviews| Index: testing/android/javatests/src/org/chromium/testing/local/GtestLoggerTest.java |
| diff --git a/testing/android/javatests/src/org/chromium/testing/local/GtestLoggerTest.java b/testing/android/javatests/src/org/chromium/testing/local/GtestLoggerTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..42fbb3682756fb387b41dbc3a36f73f1246b6c92 |
| --- /dev/null |
| +++ b/testing/android/javatests/src/org/chromium/testing/local/GtestLoggerTest.java |
| @@ -0,0 +1,150 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.testing.local; |
| + |
| +import org.junit.Assert; |
| +import org.junit.Test; |
| +import org.junit.runner.Description; |
| +import org.junit.runner.RunWith; |
| +import org.junit.runners.BlockJUnit4ClassRunner; |
| + |
| +import java.io.ByteArrayOutputStream; |
| +import java.io.PrintStream; |
| + |
| +import java.util.Comparator; |
| +import java.util.HashSet; |
| +import java.util.Set; |
| +import java.util.TreeSet; |
| + |
| +/** |
| + * Unit tests for GtestLogger. |
| + */ |
| +@RunWith(BlockJUnit4ClassRunner.class) |
| +public class GtestLoggerTest { |
|
nyquist
2014/09/19 22:21:45
Thanks! I think this is helpful, since in fact oth
|
| + |
| + @Test |
| + public void testTestStarted() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
|
nyquist
2014/09/19 22:21:45
Optional: This is fine with me, but maybe just use
jbudorick
2014/09/20 00:11:29
discussed offline, sticking with this impl.
|
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testStarted( |
| + Description.createTestDescription(GtestLoggerTest.class, "testTestStarted")); |
| + Assert.assertEquals( |
| + "[ RUN ] org.chromium.testing.local.GtestLoggerTest.testTestStarted\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestFinishedPassed() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
|
nyquist
2014/09/19 22:21:45
Optional: This seems to be repeated. Could you put
jbudorick
2014/09/20 00:11:29
I thought about this too. I was on the fence, as l
nyquist
2014/09/22 23:32:09
I see.
Now that I see it, I do agree it loses a bi
jbudorick
2014/09/22 23:53:01
Reverting to non-@Before version.
|
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testFinished( |
| + Description.createTestDescription(GtestLoggerTest.class, "testTestFinishedPassed"), |
| + true, 123); |
| + Assert.assertEquals( |
| + "[ OK ] org.chromium.testing.local.GtestLoggerTest.testTestFinishedPassed" + |
| + " (123 ms)\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestFinishedFailed() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testFinished( |
| + Description.createTestDescription(GtestLoggerTest.class, "testTestFinishedPassed"), |
| + false, 123); |
| + Assert.assertEquals( |
| + "[ FAILED ] org.chromium.testing.local.GtestLoggerTest.testTestFinishedPassed" + |
| + " (123 ms)\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestCaseStarted() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testCaseStarted( |
| + Description.createSuiteDescription(GtestLoggerTest.class), 456); |
| + Assert.assertEquals( |
| + "[----------] Run 456 test cases from org.chromium.testing.local.GtestLoggerTest\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestCaseFinished() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testCaseFinished( |
| + Description.createSuiteDescription(GtestLoggerTest.class), 456, 123); |
| + Assert.assertEquals( |
| + "[----------] Run 456 test cases from org.chromium.testing.local.GtestLoggerTest" + |
| + " (123 ms)\n\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestRunStarted() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testRunStarted(1234); |
| + Assert.assertEquals( |
| + "[==========] Running 1234 tests.\n" + |
| + "[----------] Global test environment set-up.\n\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestRunFinishedNoFailures() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + loggerUnderTest.testRunFinished(1234, new HashSet<Description>(), 4321); |
| + Assert.assertEquals( |
| + "[----------] Global test environment tear-down.\n" + |
| + "[==========] 1234 tests ran. (4321 ms total)\n" + |
| + "[ PASSED ] 1234 tests.\n", |
| + actual.toString()); |
| + } |
| + |
| + @Test |
| + public void testTestRunFinishedWithFailures() { |
| + ByteArrayOutputStream actual = new ByteArrayOutputStream(); |
| + GtestLogger loggerUnderTest = new GtestLogger(new PrintStream(actual)); |
| + |
| + Set<Description> failures = new TreeSet<Description>(new DescriptionComparator()); |
| + failures.add(Description.createTestDescription( |
| + "GtestLoggerTest", "testTestRunFinishedNoFailures")); |
| + failures.add(Description.createTestDescription( |
| + "GtestLoggerTest", "testTestRunFinishedWithFailures")); |
| + |
| + loggerUnderTest.testRunFinished(1232, failures, 4312); |
| + Assert.assertEquals( |
| + "[----------] Global test environment tear-down.\n" + |
| + "[==========] 1234 tests ran. (4312 ms total)\n" + |
| + "[ PASSED ] 1232 tests.\n" + |
| + "[ FAILED ] 2 tests.\n" + |
| + "[ FAILED ] GtestLoggerTest.testTestRunFinishedNoFailures\n" + |
| + "[ FAILED ] GtestLoggerTest.testTestRunFinishedWithFailures\n" + |
| + "\n", |
| + actual.toString()); |
| + } |
| + |
| + private static class DescriptionComparator implements Comparator<Description> { |
| + |
| + private static String toGtestStyleString(Description d) { |
| + return d.getClassName() + "." + d.getMethodName(); |
| + } |
| + |
| + @Override |
| + public int compare(Description o1, Description o2) { |
| + return toGtestStyleString(o1).compareTo(toGtestStyleString(o2)); |
| + } |
| + |
| + @Override |
| + public boolean equals(Object obj) { |
| + return obj.getClass() == this.getClass(); |
| + } |
| + } |
| +} |
| + |