diff --git a/README.html b/README.html index b022131e4e28..7674273f6c61 100644 --- a/README.html +++ b/README.html @@ -3,19 +3,19 @@ - - JUnit 3.6 + + JUnit 3.7

JUnit -3.6 +3.7 @ SourceForge Logo


-
03/27/2001 +
05/18/2001

JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.

-Summary of Changes between 3.5 and 3.6

+Summary of Changes between 3.6 and 3.7 + +

+GUI

+ + + +

+Framework

+ + + +

+Text Runner

+ + + +

+Fixed Bugs (SourceForge Bug Tracker Ids)

+    [420315] No trace when fail with message... +
    [419375] reload warning lags +
    [418849] Classloader warning too obtrusive +
    [417978] constructor stack trace, please +
    [415103] Reload checkbox should be ignored in VAJ +
    [414954] error reporting when invoking suite() +
    [407296] Make doRun() public +
    [227578] rmi callbacks fail since TestCase has no +noArg constructor +
    [422603] Decorated decorators bug +

+Summary of Changes between 3.5 and 3.6

TestRunner

diff --git a/build.xml b/build.xml index 3e97ba04458b..7fe5ad1c1259 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,7 @@ - + diff --git a/doc/cookbook/cookbook.htm b/doc/cookbook/cookbook.htm index 101277059319..58616e5afcd3 100644 --- a/doc/cookbook/cookbook.htm +++ b/doc/cookbook/cookbook.htm @@ -160,14 +160,6 @@

suite.addTest(Kent.suite()); suite.addTest(Erich.suite()); TestResult result= suite.run(); -TestSuites don't only have to contain TestCases. They contain any object -that implements the Test interface. For example, you can create a TestSuite -in your code and I can create one in mine, and we can run them together -by creating a TestSuite that contains both: -
TestSuite suite= new TestSuite();
-suite.addTest(Kent.suite());
-suite.addTest(Erich.suite());
-TestResult result= suite.run();

TestRunner

diff --git a/doc/faq/faq.htm b/doc/faq/faq.htm index 2ca62fa88a83..2d9fb20e849d 100644 --- a/doc/faq/faq.htm +++ b/doc/faq/faq.htm @@ -158,7 +158,7 @@

for each test run. The idea is that you typically have a working set of classes that you work with and that there is a set of classes that you don't change. The list of package prefixes is defined in the properties -file junit.util.excluded.properties. As we deliver it, this file +file junit/runner/excluded.properties. As we deliver it, this file excludes the packages that come with jdk1.2 from reloading:
#
# The list of excluded package paths for the TestCaseClassLoader diff --git a/junit/awtui/TestRunner.java b/junit/awtui/TestRunner.java index a2b19f633a8a..d1b9499b06d1 100644 --- a/junit/awtui/TestRunner.java +++ b/junit/awtui/TestRunner.java @@ -39,7 +39,6 @@ public class TestRunner extends BaseTestRunner { protected Button fRerunButton; protected TextField fStatusLine; protected Checkbox fUseLoadingRunner; - protected int fNonLoadingRuns= 0; protected static Font PLAIN_FONT= new Font("dialog", Font.PLAIN, 12); private static final int GAP= 4; @@ -185,7 +184,9 @@ public void actionPerformed(ActionEvent e) { ); boolean useLoader= useReloadingTestSuiteLoader(); fUseLoadingRunner= new Checkbox("Reload classes every run", useLoader); - + if (inVAJava()) + fUseLoadingRunner.setVisible(false); + //---- second section fProgressIndicator= new ProgressBar(); @@ -334,7 +335,7 @@ public void rerun() { Class reloadedTestClass= getLoader().reload(test.getClass()); Class[] classArgs= { String.class }; Constructor constructor= reloadedTestClass.getConstructor(classArgs); - Object[] args= new Object[]{((TestCase)test).name()}; + Object[] args= new Object[]{((TestCase)test).getName()}; reloadedTest=(Test)constructor.newInstance(args); } catch(Exception e) { showInfo("Could not reload "+ test.toString()); @@ -382,8 +383,7 @@ synchronized public void runSuite() { if (fRunner != null) { fTestResult.stop(); } else { - if (!setUseLoadingRunner()) - return; + setLoading(shouldReload()); fRun.setLabel("Stop"); showInfo("Initializing..."); reset(); @@ -420,20 +420,10 @@ public void run() { } } - private boolean setUseLoadingRunner() { - setLoading(fUseLoadingRunner.getState()); - if (!fUseLoadingRunner.getState()) - fNonLoadingRuns++; - if (fNonLoadingRuns > 1) { - String message1= "Code modifications you made since the last run will be ignored."; - String message2= "It is recommended to restart the TestRunner. Do you still want to continue?"; - WarningDialog dialog= new WarningDialog(fFrame, message1, message2); - dialog.show(); - return dialog.getChoice(); - } - return true; + private boolean shouldReload() { + return !inVAJava() && fUseLoadingRunner.getState(); } - + private void setLabelValue(Label label, int value) { label.setText(Integer.toString(value)); label.invalidate(); diff --git a/junit/awtui/WarningDialog.java b/junit/awtui/WarningDialog.java deleted file mode 100644 index 1d8d3383208a..000000000000 --- a/junit/awtui/WarningDialog.java +++ /dev/null @@ -1,80 +0,0 @@ -package junit.awtui; - -import java.awt.*; -import java.awt.event.*; - -import junit.runner.Version; - -class WarningDialog extends Dialog { - private boolean fChoice; - - public WarningDialog(Frame parent, String message1, String message2) { - super(parent); - - setResizable(false); - setLayout(new GridBagLayout()); - setSize(450, 120); - setTitle("Warning"); - setModal(true); - setLocation(300, 300); - - Button yes= new Button("Yes"); - yes.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - fChoice= true; - dispose(); - } - } - ); - - Button no= new Button("No"); - no.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - fChoice= false; - dispose(); - } - } - ); - - Label label1= new Label(message1); - Label label2= new Label(message2); - - GridBagConstraints constraintsLabel1= new GridBagConstraints(); - constraintsLabel1.gridx= 0; constraintsLabel1.gridy = 0; - constraintsLabel1.gridwidth= 1; constraintsLabel1.gridheight= 1; - constraintsLabel1.anchor= GridBagConstraints.WEST; - add(label1, constraintsLabel1); - - GridBagConstraints constraintsLabel2= new GridBagConstraints(); - constraintsLabel2.gridx= 0; constraintsLabel2.gridy= 1; - constraintsLabel2.gridwidth= 2; constraintsLabel2.gridheight= 1; - constraintsLabel2.anchor= GridBagConstraints.WEST; - add(label2, constraintsLabel2); - - GridBagConstraints constraintsYes= new GridBagConstraints(); - constraintsYes.gridx= 0; constraintsYes.gridy= 2; - constraintsYes.gridwidth= 1; constraintsYes.gridheight= 1; - constraintsYes.anchor= GridBagConstraints.EAST; - add(yes, constraintsYes); - - GridBagConstraints constraintsNo= new GridBagConstraints(); - constraintsNo.gridx= 1; constraintsNo.gridy= 2; - constraintsNo.gridwidth= 1; constraintsNo.gridheight= 1; - constraintsNo.anchor= GridBagConstraints.WEST; - add(no, constraintsNo); - - addWindowListener( - new WindowAdapter() { - public void windowClosing(WindowEvent e) { - dispose(); - } - } - ); - } - - public boolean getChoice() { - return fChoice; - } -} \ No newline at end of file diff --git a/junit/framework/Assert.java b/junit/framework/Assert.java index 9cb4a9fd1d3e..a038fdbd1151 100644 --- a/junit/framework/Assert.java +++ b/junit/framework/Assert.java @@ -13,6 +13,7 @@ protected Assert() { /** * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError with the given message. + * @deprecated use assertTrue */ static public void assert(String message, boolean condition) { if (!condition) @@ -21,10 +22,28 @@ static public void assert(String message, boolean condition) { /** * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError. + * @deprecated use assertTrue + * */ static public void assert(boolean condition) { assert(null, condition); } + + /** + * Asserts that a condition is true. If it isn't it throws + * an AssertionFailedError with the given message. + */ + static public void assertTrue(String message, boolean condition) { + if (!condition) + fail(message); + } + /** + * Asserts that a condition is true. If it isn't it throws + * an AssertionFailedError. + */ + static public void assertTrue(boolean condition) { + assertTrue(null, condition); + } /** * Fails a test with the given message. */ @@ -177,7 +196,7 @@ static public void assertNotNull(Object object) { * Asserts that an object isn't null. */ static public void assertNotNull(String message, Object object) { - assert(message, object != null); + assertTrue(message, object != null); } /** * Asserts that an object is null. @@ -189,7 +208,7 @@ static public void assertNull(Object object) { * Asserts that an object is null. */ static public void assertNull(String message, Object object) { - assert(message, object == null); + assertTrue(message, object == null); } /** * Asserts that two objects refer to the same object. If they are not diff --git a/junit/framework/TestCase.java b/junit/framework/TestCase.java index 246be52daa9d..c8d68e79992d 100644 --- a/junit/framework/TestCase.java +++ b/junit/framework/TestCase.java @@ -75,7 +75,16 @@ public abstract class TestCase extends Assert implements Test { /** * the name of the test case */ - private final String fName; + private String fName; + + /** + * No-arg constructor to enable serialization. This method + * is not intended to be used by mere mortals. + */ + TestCase() { + fName= null; + } + /** * Constructs a test case with the given name. */ @@ -99,6 +108,7 @@ protected TestResult createResult() { } /** * Gets the name of the test case. + * @deprecated use getName() */ public String name() { return fName; @@ -182,4 +192,20 @@ protected void tearDown() throws Exception { public String toString() { return name()+"("+getClass().getName()+")"; } + /** + * Gets the name of a TestCase + * @return returns a String + */ + public String getName() { + return fName; + } + + /** + * Sets the name of a TestCase + * @param name The name to set + */ + public void setName(String name) { + fName= name; + } + } \ No newline at end of file diff --git a/junit/framework/TestSuite.java b/junit/framework/TestSuite.java index c71dd4bbe34e..b8937c04e936 100644 --- a/junit/framework/TestSuite.java +++ b/junit/framework/TestSuite.java @@ -2,7 +2,7 @@ import java.util.Vector; import java.util.Enumeration; -import java.lang.reflect.*; +import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.*; /** * A TestSuite is a Composite of Tests. @@ -99,11 +99,11 @@ private void addTestMethod(Method m, Vector names, Constructor constructor) { try { addTest((Test)constructor.newInstance(args)); } catch (InstantiationException e) { - addTest(warning("Cannot instantiate test case: "+name+" ("+e.toString()+")")); + addTest(warning("Cannot instantiate test case: "+name+" ("+exceptionToString(e)+")")); } catch (InvocationTargetException e) { - addTest(warning("Exception in constructor: "+name+" ("+e.getTargetException().toString()+")")); + addTest(warning("Exception in constructor: "+name+" ("+exceptionToString(e.getTargetException())+")")); } catch (IllegalAccessException e) { - addTest(warning("Cannot access test case: "+name+" ("+e.toString()+")")); + addTest(warning("Cannot access test case: "+name+" ("+exceptionToString(e)+")")); } } else { // almost a test method @@ -111,6 +111,17 @@ private void addTestMethod(Method m, Vector names, Constructor constructor) { addTest(warning("Test method isn't public: "+m.getName())); } } + + /** + * Converts the stack trace into a string + */ + private String exceptionToString(Throwable t) { + StringWriter stringWriter= new StringWriter(); + PrintWriter writer= new PrintWriter(stringWriter); + t.printStackTrace(writer); + return stringWriter.toString(); + + } /** * Counts the number of test cases that will be run by this test. */ @@ -185,8 +196,15 @@ public String toString() { return getName(); return super.toString(); } - - + + /** + * Sets the name of the suite. + * @param name The name to set + */ + public void setName(String name) { + fName= name; + } + /** * Returns the name of the suite. Not all * test suites have a name and this method diff --git a/junit/runner/BaseTestRunner.java b/junit/runner/BaseTestRunner.java index ecdc52b2cfc1..018021b92a34 100644 --- a/junit/runner/BaseTestRunner.java +++ b/junit/runner/BaseTestRunner.java @@ -53,10 +53,16 @@ public Test getTest(String suiteClassName) { test= (Test)suiteMethod.invoke(null, new Class[0]); // static method if (test == null) return test; - } catch(Exception e) { - runFailed("Could not invoke the suite() method"); + } + catch (InvocationTargetException e) { + runFailed("Failed to invoke suite():" + e.getTargetException().toString()); + return null; + } + catch (IllegalAccessException e) { + runFailed("Failed to invoke suite():" + e.toString()); return null; } + clearStatus(); return test; } @@ -95,7 +101,7 @@ protected String processArguments(String[] args) { /** * Sets the loading behaviour of the test runner */ - protected void setLoading(boolean enable) { + public void setLoading(boolean enable) { fLoading= enable; } /** diff --git a/junit/runner/TestCaseClassLoader.java b/junit/runner/TestCaseClassLoader.java index a9ec895a7f36..531d6956a52d 100644 --- a/junit/runner/TestCaseClassLoader.java +++ b/junit/runner/TestCaseClassLoader.java @@ -121,7 +121,7 @@ private byte[] lookupClassData(String className) throws ClassNotFoundException { if (data != null) return data; } - throw new ClassNotFoundException(); + throw new ClassNotFoundException(className); } boolean isJar(String pathEntry) { diff --git a/junit/runner/Version.java b/junit/runner/Version.java index 03dba646d344..e69de29bb2d1 100644 --- a/junit/runner/Version.java +++ b/junit/runner/Version.java @@ -1,14 +0,0 @@ -package junit.runner; - -/** - * This class defines the current version of JUnit - */ -public class Version { - private Version() { - // don't instantiate - } - - public static String id() { - return "@version@"; - } -} \ No newline at end of file diff --git a/junit/samples/SimpleTest.java b/junit/samples/SimpleTest.java index ecfbed359221..de1f0cbee011 100644 --- a/junit/samples/SimpleTest.java +++ b/junit/samples/SimpleTest.java @@ -44,7 +44,7 @@ public static Test suite() { public void testAdd() { double result= fValue1 + fValue2; // forced failure result == 5 - assert(result == 6); + assertTrue(result == 6); } public void testDivideByZero() { int zero= 0; diff --git a/junit/samples/VectorTest.java b/junit/samples/VectorTest.java index 18761f8b1fdd..598c5c4eaa49 100644 --- a/junit/samples/VectorTest.java +++ b/junit/samples/VectorTest.java @@ -32,20 +32,20 @@ public void testCapacity() { int size= fFull.size(); for (int i= 0; i < 100; i++) fFull.addElement(new Integer(i)); - assert(fFull.size() == 100+size); + assertTrue(fFull.size() == 100+size); } public void testClone() { Vector clone= (Vector)fFull.clone(); - assert(clone.size() == fFull.size()); - assert(clone.contains(new Integer(1))); + assertTrue(clone.size() == fFull.size()); + assertTrue(clone.contains(new Integer(1))); } public void testContains() { - assert(fFull.contains(new Integer(1))); - assert(!fEmpty.contains(new Integer(1))); + assertTrue(fFull.contains(new Integer(1))); + assertTrue(!fEmpty.contains(new Integer(1))); } public void testElementAt() { Integer i= (Integer)fFull.elementAt(0); - assert(i.intValue() == 1); + assertTrue(i.intValue() == 1); try { Integer j= (Integer)fFull.elementAt(fFull.size()); @@ -57,11 +57,11 @@ public void testElementAt() { public void testRemoveAll() { fFull.removeAllElements(); fEmpty.removeAllElements(); - assert(fFull.isEmpty()); - assert(fEmpty.isEmpty()); + assertTrue(fFull.isEmpty()); + assertTrue(fEmpty.isEmpty()); } public void testRemoveElement() { fFull.removeElement(new Integer(3)); - assert(!fFull.contains(new Integer(3)) ); + assertTrue(!fFull.contains(new Integer(3)) ); } } \ No newline at end of file diff --git a/junit/samples/money/MoneyTest.java b/junit/samples/money/MoneyTest.java index c698b8455f6c..e7357f1e0dcc 100644 --- a/junit/samples/money/MoneyTest.java +++ b/junit/samples/money/MoneyTest.java @@ -32,7 +32,7 @@ public void testBagMultiply() { MoneyBag expected= new MoneyBag(bag); assertEquals(expected, fMB1.multiply(2)); assertEquals(fMB1, fMB1.multiply(1)); - assert(fMB1.multiply(0).isZero()); + assertTrue(fMB1.multiply(0).isZero()); } public void testBagNegate() { // {[12 CHF][7 USD]} negate == {[-12 CHF][-7 USD]} @@ -59,10 +59,10 @@ public void testBagSumAdd() { assertEquals(expected, fMB1.add(fMB2)); } public void testIsZero() { - assert(fMB1.subtract(fMB1).isZero()); + assertTrue(fMB1.subtract(fMB1).isZero()); Money bag[] = { new Money (0, "CHF"), new Money (0, "USD") }; - assert(new MoneyBag(bag).isZero()); + assertTrue(new MoneyBag(bag).isZero()); } public void testMixedSimpleAdd() { // [12 CHF] + [7 USD] == {[12 CHF][7 USD]} @@ -71,29 +71,29 @@ public void testMixedSimpleAdd() { assertEquals(expected, f12CHF.add(f7USD)); } public void testMoneyBagEquals() { - assert(!fMB1.equals(null)); + assertTrue(!fMB1.equals(null)); assertEquals(fMB1, fMB1); MoneyBag equal= new MoneyBag(new Money(12, "CHF"), new Money(7, "USD")); - assert(fMB1.equals(equal)); - assert(!fMB1.equals(f12CHF)); - assert(!f12CHF.equals(fMB1)); - assert(!fMB1.equals(fMB2)); + assertTrue(fMB1.equals(equal)); + assertTrue(!fMB1.equals(f12CHF)); + assertTrue(!f12CHF.equals(fMB1)); + assertTrue(!fMB1.equals(fMB2)); } public void testMoneyBagHash() { MoneyBag equal= new MoneyBag(new Money(12, "CHF"), new Money(7, "USD")); assertEquals(fMB1.hashCode(), equal.hashCode()); } public void testMoneyEquals() { - assert(!f12CHF.equals(null)); + assertTrue(!f12CHF.equals(null)); Money equalMoney= new Money(12, "CHF"); assertEquals(f12CHF, f12CHF); assertEquals(f12CHF, equalMoney); assertEquals(f12CHF.hashCode(), equalMoney.hashCode()); - assert(!f12CHF.equals(f14CHF)); + assertTrue(!f12CHF.equals(f14CHF)); } public void testMoneyHash() { - assert(!f12CHF.equals(null)); + assertTrue(!f12CHF.equals(null)); Money equal= new Money(12, "CHF"); assertEquals(f12CHF.hashCode(), equal.hashCode()); } diff --git a/junit/swingui/CounterPanel.java b/junit/swingui/CounterPanel.java index df17ee0295f1..2088eb705754 100644 --- a/junit/swingui/CounterPanel.java +++ b/junit/swingui/CounterPanel.java @@ -12,6 +12,7 @@ public class CounterPanel extends Panel { private JTextField fNumberOfErrors; private JTextField fNumberOfFailures; private JTextField fNumberOfRuns; + private int fTotal; public CounterPanel() { super(new GridLayout(2, 3)); @@ -39,10 +40,15 @@ public void reset() { setLabelValue(fNumberOfErrors, 0); setLabelValue(fNumberOfFailures, 0); setLabelValue(fNumberOfRuns, 0); + fTotal= 0; + } + + public void setTotal(int value) { + fTotal= value; } public void setRunValue(int value) { - setLabelValue(fNumberOfRuns, value); + fNumberOfRuns.setText(Integer.toString(value) + "/" + fTotal); } public void setErrorValue(int value) { diff --git a/junit/swingui/TestRunner.java b/junit/swingui/TestRunner.java index 66a2fc69f24d..e79b51b2a39e 100644 --- a/junit/swingui/TestRunner.java +++ b/junit/swingui/TestRunner.java @@ -43,7 +43,6 @@ public class TestRunner extends BaseTestRunner implements TestRunContext { private JTabbedPane fTestViewTab; private JCheckBox fUseLoadingRunner; private Vector fTestRunViews= new Vector(); // view associated with tab in tabbed pane - private int fNonLoadingRuns= 0; private static Font PLAIN_FONT= StatusLine.PLAIN_FONT; private static Font BOLD_FONT= StatusLine.BOLD_FONT; private static final int GAP= 4; @@ -147,10 +146,6 @@ private void revealFailure(Test test) { } } - public void changedUpdate(DocumentEvent event) { - textChanged(); - } - protected void aboutToStart(final Test testSuite) { for (Enumeration e= fTestRunViews.elements(); e.hasMoreElements(); ) { TestRunView v= (TestRunView) e.nextElement(); @@ -273,6 +268,8 @@ protected JCheckBox createUseLoaderCheckBox() { boolean useLoader= useReloadingTestSuiteLoader(); JCheckBox box= new JCheckBox("Reload classes every run", useLoader); box.setToolTipText("Use a custom class loader to reload the classes for every run"); + if (inVAJava()) + box.setVisible(false); return box; } @@ -394,7 +391,6 @@ protected JFrame createUI(String suiteName) { Component browseButton= createBrowseButton(); fUseLoadingRunner= createUseLoaderCheckBox(); - fProgressIndicator= new ProgressBar(); fCounterPanel= createCounterPanel(); @@ -564,7 +560,7 @@ private void rerunTest(Test test) { try { Class reloadedTestClass= getLoader().reload(test.getClass()); Class[] classArgs= { String.class }; - Object[] args= new Object[]{((TestCase)test).name()}; + Object[] args= new Object[]{((TestCase)test).getName()}; Constructor constructor= reloadedTestClass.getConstructor(classArgs); reloadedTest=(Test)constructor.newInstance(args); } catch(Exception e) { @@ -609,8 +605,7 @@ synchronized public void runSuite() { if (fRunner != null) { fTestResult.stop(); } else { - if (!setUseLoadingRunner()) - return; + setLoading(shouldReload()); reset(); showInfo("Load Test Case..."); final String suiteName= getSuiteText(); @@ -622,19 +617,10 @@ synchronized public void runSuite() { } } - private boolean setUseLoadingRunner() { - setLoading(fUseLoadingRunner.isSelected()); - if (!fUseLoadingRunner.isSelected()) - fNonLoadingRuns++; - if (fNonLoadingRuns > 1) { - String message= "You are running the tests more than once with the standard class loader.\n"+ - "Code modifications you made since the last run will be ignored.\n"+ - "It is recommended to restart the TestRunner.\nDo you still want to continue?"; - int returnCode= JOptionPane.showConfirmDialog(fFrame, message, "Warning", JOptionPane.YES_NO_OPTION); - return returnCode == JOptionPane.YES_OPTION; - } - return true; + private boolean shouldReload() { + return !inVAJava() && fUseLoadingRunner.isSelected(); } + synchronized protected void runTest(final Test testSuite) { if (fRunner != null) { @@ -758,7 +744,9 @@ private void start(final Test test) { SwingUtilities.invokeLater( new Runnable() { public void run() { - fProgressIndicator.start(test.countTestCases()); + int total= test.countTestCases(); + fProgressIndicator.start(total); + fCounterPanel.setTotal(total); } } ); diff --git a/junit/swingui/TestTreeModel.java b/junit/swingui/TestTreeModel.java index f8ff53f5c308..d0c850479ca3 100644 --- a/junit/swingui/TestTreeModel.java +++ b/junit/swingui/TestTreeModel.java @@ -120,16 +120,16 @@ public boolean isLeaf(Object node) { /** * Tests if the node is a TestSuite. */ - protected TestSuite isTestSuite(Object node) { + TestSuite isTestSuite(Object node) { if (node instanceof TestSuite) return (TestSuite)node; if (node instanceof TestDecorator) { - Object baseTest= ((TestDecorator)node).getTest(); - if (baseTest instanceof TestSuite) - return (TestSuite)baseTest; + Test baseTest= ((TestDecorator)node).getTest(); + return isTestSuite(baseTest); } return null; } + /** * Called when the value of the model object was changed in the view */ diff --git a/junit/tests/ClassLoaderTest.java b/junit/tests/ClassLoaderTest.java index e044608c0e3d..a7220817b668 100644 --- a/junit/tests/ClassLoaderTest.java +++ b/junit/tests/ClassLoaderTest.java @@ -17,10 +17,10 @@ private boolean isTestCaseClassLoader(ClassLoader cl) { return (cl != null && cl.getClass().getName().equals(junit.runner.TestCaseClassLoader.class.getName())); } private void verifyApplicationClassLoadedByTestLoader() { - assert(isTestCaseClassLoader(getClass().getClassLoader())); + assertTrue(isTestCaseClassLoader(getClass().getClassLoader())); } private void verifySystemClassNotLoadedByTestLoader() { - assert(!isTestCaseClassLoader(Object.class.getClassLoader())); - assert(!isTestCaseClassLoader(TestCase.class.getClassLoader())); + assertTrue(!isTestCaseClassLoader(Object.class.getClassLoader())); + assertTrue(!isTestCaseClassLoader(TestCase.class.getClassLoader())); } } \ No newline at end of file diff --git a/junit/tests/ExceptionTestCaseTest.java b/junit/tests/ExceptionTestCaseTest.java index 4149546d65ff..7a836be0bf56 100644 --- a/junit/tests/ExceptionTestCaseTest.java +++ b/junit/tests/ExceptionTestCaseTest.java @@ -38,13 +38,13 @@ public void testExceptionSubclass() { ExceptionTestCase test= new ThrowExceptionTestCase("test", IndexOutOfBoundsException.class); TestResult result= test.run(); assertEquals(1, result.runCount()); - assert(result.wasSuccessful()); + assertTrue(result.wasSuccessful()); } public void testExceptionTest() { ExceptionTestCase test= new ThrowExceptionTestCase("test", IndexOutOfBoundsException.class); TestResult result= test.run(); assertEquals(1, result.runCount()); - assert(result.wasSuccessful()); + assertTrue(result.wasSuccessful()); } public void testFailure() { ExceptionTestCase test= new ThrowRuntimeExceptionTestCase("test", IndexOutOfBoundsException.class); diff --git a/junit/tests/ExtensionTest.java b/junit/tests/ExtensionTest.java index 723cf02f844a..9b735c5f676a 100644 --- a/junit/tests/ExtensionTest.java +++ b/junit/tests/ExtensionTest.java @@ -32,7 +32,7 @@ public void runTest() { TestResult result= new TestResult(); wrapper.run(result); - assert(!result.wasSuccessful()); + assertTrue(!result.wasSuccessful()); } public void testRunningErrorsInTestSetup() { TestCase failure= new TestCase("failure") { @@ -71,7 +71,7 @@ public void setUp() { TestResult result= new TestResult(); wrapper.run(result); - assert(!wrapper.fTornDown); + assertTrue(!wrapper.fTornDown); } public void testSetupErrorInTestSetup() { WasRun test= new WasRun(""); @@ -85,7 +85,7 @@ public void setUp() { TestResult result= new TestResult(); wrapper.run(result); - assert(!test.fWasRun); - assert(!result.wasSuccessful()); + assertTrue(!test.fWasRun); + assertTrue(!result.wasSuccessful()); } } \ No newline at end of file diff --git a/junit/tests/LoadedFromJar.java b/junit/tests/LoadedFromJar.java index 07313622d153..685c1f8ab785 100644 --- a/junit/tests/LoadedFromJar.java +++ b/junit/tests/LoadedFromJar.java @@ -14,6 +14,6 @@ private boolean isTestCaseClassLoader(ClassLoader cl) { return (cl != null && cl.getClass().getName().equals(junit.runner.TestCaseClassLoader.class.getName())); } private void verifyApplicationClassLoadedByTestLoader() { - assert(isTestCaseClassLoader(getClass().getClassLoader())); + assertTrue(isTestCaseClassLoader(getClass().getClassLoader())); } } \ No newline at end of file diff --git a/junit/tests/SuiteTest.java b/junit/tests/SuiteTest.java index 22c5b6509bdd..84f3603317e8 100644 --- a/junit/tests/SuiteTest.java +++ b/junit/tests/SuiteTest.java @@ -33,28 +33,28 @@ public static Test suite() { public void testInheritedTests() { TestSuite suite= new TestSuite(InheritedTestCase.class); suite.run(fResult); - assert(fResult.wasSuccessful()); + assertTrue(fResult.wasSuccessful()); assertEquals(2, fResult.runCount()); } public void testNoTestCaseClass() { Test t= new TestSuite(NoTestCaseClass.class); t.run(fResult); assertEquals(1, fResult.runCount()); // warning test - assert(! fResult.wasSuccessful()); + assertTrue(! fResult.wasSuccessful()); } public void testNoTestCases() { Test t= new TestSuite(NoTestCases.class); t.run(fResult); - assert(fResult.runCount() == 1); // warning test - assert(fResult.failureCount() == 1); - assert(! fResult.wasSuccessful()); + assertTrue(fResult.runCount() == 1); // warning test + assertTrue(fResult.failureCount() == 1); + assertTrue(! fResult.wasSuccessful()); } public void testNotExistingTestCase() { Test t= new SuiteTest("notExistingMethod"); t.run(fResult); - assert(fResult.runCount() == 1); - assert(fResult.failureCount() == 1); - assert(fResult.errorCount() == 0); + assertTrue(fResult.runCount() == 1); + assertTrue(fResult.failureCount() == 1); + assertTrue(fResult.errorCount() == 0); } public void testNotPublicTestCase() { TestSuite suite= new TestSuite(NotPublicTestCase.class); @@ -63,15 +63,15 @@ public void testNotPublicTestCase() { } public void testNotVoidTestCase() { TestSuite suite= new TestSuite(NotVoidTestCase.class); - assert(suite.countTestCases() == 1); + assertTrue(suite.countTestCases() == 1); } public void testOneTestCase() { Test t= new TestSuite(OneTestCase.class); t.run(fResult); - assert(fResult.runCount() == 1); - assert(fResult.failureCount() == 0); - assert(fResult.errorCount() == 0); - assert(fResult.wasSuccessful()); + assertTrue(fResult.runCount() == 1); + assertTrue(fResult.failureCount() == 0); + assertTrue(fResult.errorCount() == 0); + assertTrue(fResult.wasSuccessful()); } public void testShadowedTests() { TestSuite suite= new TestSuite(OverrideTestCase.class); diff --git a/junit/tests/TestCaseTest.java b/junit/tests/TestCaseTest.java index 2373ea334396..9029d7b195c2 100644 --- a/junit/tests/TestCaseTest.java +++ b/junit/tests/TestCaseTest.java @@ -51,7 +51,7 @@ protected void runTest() { } }; verifyError(fails); - assert(fails.fTornDown); + assertTrue(fails.fTornDown); } public void testSetupFails() { TestCase fails= new TestCase("success") { @@ -82,7 +82,7 @@ protected void runTest() { public void testTearDownAfterError() { TornDown fails= new TornDown("fails"); verifyError(fails); - assert(fails.fTornDown); + assertTrue(fails.fTornDown); } public void testTearDownFails() { @@ -102,30 +102,30 @@ protected void setUp() { } }; verifyError(fails); - assert(!fails.fTornDown); + assertTrue(!fails.fTornDown); } public void testWasRun() { WasRun test= new WasRun(""); test.run(); - assert(test.fWasRun); + assertTrue(test.fWasRun); } void verifyError(TestCase test) { TestResult result= test.run(); - assert(result.runCount() == 1); - assert(result.failureCount() == 0); - assert(result.errorCount() == 1); + assertTrue(result.runCount() == 1); + assertTrue(result.failureCount() == 0); + assertTrue(result.errorCount() == 1); } void verifyFailure(TestCase test) { TestResult result= test.run(); - assert(result.runCount() == 1); - assert(result.failureCount() == 1); - assert(result.errorCount() == 0); + assertTrue(result.runCount() == 1); + assertTrue(result.failureCount() == 1); + assertTrue(result.errorCount() == 0); } void verifySuccess(TestCase test) { TestResult result= test.run(); - assert(result.runCount() == 1); - assert(result.failureCount() == 0); - assert(result.errorCount() == 0); + assertTrue(result.runCount() == 1); + assertTrue(result.failureCount() == 0); + assertTrue(result.errorCount() == 0); } diff --git a/junit/tests/TextRunnerTest.java b/junit/tests/TextRunnerTest.java index 00373c93e717..e6baf35cfe7e 100644 --- a/junit/tests/TextRunnerTest.java +++ b/junit/tests/TextRunnerTest.java @@ -30,7 +30,7 @@ void execTest(String testClass, boolean success) throws Exception { int b; while((b= i.read()) != -1) ; //System.out.write(b); - assert((p.waitFor() == 0) == success); + assertTrue((p.waitFor() == 0) == success); } diff --git a/junit/textui/TestRunner.java b/junit/textui/TestRunner.java index 30da34ccbadb..7ee9597e014a 100644 --- a/junit/textui/TestRunner.java +++ b/junit/textui/TestRunner.java @@ -67,7 +67,7 @@ protected TestResult createTestResult() { return new TestResult(); } - protected TestResult doRun(Test suite, boolean wait) { + public TestResult doRun(Test suite, boolean wait) { TestResult result= createTestResult(); result.addListener(this); long startTime= System.currentTimeMillis(); @@ -80,6 +80,11 @@ protected TestResult doRun(Test suite, boolean wait) { writer().println(); + pause(wait); + return result; + } + + protected void pause(boolean wait) { if (wait) { writer().println(" to continue"); try { @@ -88,7 +93,6 @@ protected TestResult doRun(Test suite, boolean wait) { catch(Exception e) { } } - return result; } public synchronized void startTest(Test test) { @@ -154,12 +158,7 @@ public void printFailures(TestResult result) { TestFailure failure= (TestFailure) e.nextElement(); writer().print(i + ") " + failure.failedTest()); Throwable t= failure.thrownException(); - if (t.getMessage() != null) - writer().println(" \"" + truncate(t.getMessage()) + "\""); - else { - writer().println(); - writer().print(getFilteredTrace(failure.thrownException())); - } + writer().print(getFilteredTrace(failure.thrownException())); } } } @@ -201,7 +200,7 @@ static public void run(Test suite) { aTestRunner.doRun(suite, false); } /** - * Runs a single test and waits until the users + * Runs a single test and waits until the user * types RETURN. */ static public void runAndWait(Test suite) {