001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.tf.tests;
024:
025: import java.util.*;
026: import drjava.tf.*;
027: import drjava.util.TestUtil;
028: import junit.framework.TestCase;
029:
030: /** a JUnit test that tests the Test Framework */
031: public class TFTest extends TestCase {
032: public TFTest(String name) {
033: super (name);
034: }
035:
036: /** tests all features at once */
037: public void testComplete() throws Exception {
038: String linesep = System.getProperty("line.separator");
039:
040: TestResult result = TF.runTest("src/drjava/tf/tests/simple.tf");
041:
042: // 2 failures in main test + 1 failure in subtest
043: assertEquals(3, result.getTotalNumberOfFailures());
044:
045: // Check main test
046: assertEquals("src/drjava/tf/tests/simple.tf", result
047: .getTestName());
048: List<TestEvent> events = result.getEvents();
049: TestUtil.checkList(events, new TestEvent[] {
050: new TestEvent(TestEvent.SYSTEMOUT,
051: "A message on System.out" + linesep),
052: new TestEvent(TestEvent.SYSTEMERR,
053: "A message on System.err" + linesep),
054: new TestEvent(TestEvent.ERROR, "Test error"),
055: new TestEvent(TestEvent.SYSTEMOUT,
056: "Another message on System.out" + linesep),
057: new TestEvent(TestEvent.SYSTEMERR,
058: "Another message on System.err" + linesep),
059: new TestEvent(TestEvent.EXCEPTION,
060: "java.lang.Exception: An exception"), });
061:
062: assertEquals(false, events.get(0).isFailure());
063: assertEquals(false, events.get(1).isFailure());
064: assertEquals(true, events.get(2).isFailure());
065: assertEquals(true, events.get(5).isFailure());
066:
067: //XXXassertEquals(12, events.get(2).getLineNumber());
068:
069: // Check subtest list
070: List<TestResult> subtests = result.getSubtests();
071: assertEquals(1, subtests.size());
072:
073: // Check subtest
074: result = subtests.get(0);
075: assertEquals("testSomething", result.getTestName());
076: TestUtil.checkList(result.getEvents(), new TestEvent[] {
077: new TestEvent(TestEvent.ERROR, "Some error"),
078: new TestEvent(TestEvent.SYSTEMOUT,
079: "System out in subtest" + linesep), });
080: }
081:
082: public void testAsserts() throws Exception {
083: TestResult result = TF
084: .runTest("src/drjava/tf/tests/asserts.tf");
085: TestUtil.checkList(result.getEvents(),
086: new TestEvent[] { new TestEvent(TestEvent.ERROR,
087: "expected:<1> but was:<2>"), });
088: }
089:
090: public void testSetUp() throws Exception {
091: TestResult result = TF.runTest("src/drjava/tf/tests/setup.tf");
092: TestUtil.checkList(result.getAllEvents(), new TestEvent[] {
093: new TestEvent(TestEvent.ERROR, "setUp"),
094: new TestEvent(TestEvent.ERROR, "test1"),
095: new TestEvent(TestEvent.ERROR, "setUp"),
096: new TestEvent(TestEvent.ERROR, "test2"), });
097: }
098:
099: public void testBench() throws Exception {
100: TestResult result = TF.runTest("src/drjava/tf/tests/bench.tf");
101:
102: List<TestResult> subtests = result.getSubtests();
103: assertEquals(1, subtests.size());
104:
105: result = subtests.get(0);
106: assertEquals("benchSomething", result.getTestName());
107: assertEquals("Waste 100 ms", result.getDescription());
108: assertEquals(100.0, result.getRuntime(), 1.0);
109: }
110: }
|