Skip to content

Commit

Permalink
Add a checkbox to UI test runner so that user can switch
Browse files Browse the repository at this point in the history
between the standard and loading testcase class loader.
[ #229753 ] assertEquals on NaN and Infinity does not work correctly
[ #229287 ] Class Name too long "SimpleClassPathTestCollector"
[ #229609 ] Stack Filtering missing in textui.TesRunner
[ #229753 ] assertEquals on NaN and Infinity does not work correctly.
[ #229870 ] Clicking on ... after tests failed gives NPE
[ #229974 ] Incorrect icon shown for first element in Swing GUI
[ #230581 ] swingui.TestTreeModel: results of decorated testcases...
[ #230971 ] Make junit.extensions.TestDecorator.getTest() public
[ #231569 ] DocBug: JUnit Test Infected: Programmers Love Writing Tests
[ #232645 ] BaseTestRunner.getTest loses exception information
[ #233094 ] TestSuite masks exceptions
[ #410967 ] No icon provided for first test
[ #230745 ] ClassPathTestCollector sometimes lists classes in duplicate
  • Loading branch information
egamma committed Apr 1, 2001
1 parent 1e752dc commit bfc94ee
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 113 deletions.
26 changes: 20 additions & 6 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="Author" content="Erich Gamma">
<title>JUnit 3.4</title>
<title>JUnit 3.6</title>
</head>
<body>

<h1>
<b><font color="#00CC00">J</font><font color="#FF0000">U</font><font color="#000000">nit
3.5
3.6
</font><font color="#808080">@</font><font color="#000000">&nbsp;</font></b><!--webbot bot="HTMLMarkup" startspan --><a href="http://sourceforge.net"><img SRC="sflogo.php" ALT="SourceForge Logo" BORDER=0 height=31 width=88></a><!--webbot
bot="HTMLMarkup" endspan --></h1>

<hr WIDTH="100%">
<br>01/03/2001
<br>03/27/2001
<p>JUnit is a simple framework to write repeatable tests. It is an instance
of the xUnit architecture for unit testing frameworks.
<ul>
Expand All @@ -36,7 +36,21 @@ <h1>
</ul>

<h2>
<a NAME="Summary of"></a>Summary of Changes between 3.4 and 3.5</h2>
<a NAME="Summary of"></a>Summary of Changes between 3.5 and 3.6</h2>

<ul>
<li>
The UI TestRunners no longer use the loading class loader by default. To
enable the loading class loader can either use the <b>-loading </b>command
line option or set loading option in the&nbsp; <b>junit.properties</b>
to true.</li>

<li>
</li>
</ul>

<h2>
Summary of Changes between 3.4 and 3.5</h2>

<h3>
Framework</h3>
Expand Down Expand Up @@ -89,8 +103,8 @@ <h3>
has a static <b>suite</b> method.</li>
</ul>
By default the simple the test collector is used. The loading collector
is more precise but much slower than the simple one. The loading collector doesn't scale
up when many classes are available on the class path.
is more precise but much slower than the simple one. The loading collector
doesn't scale up when many classes are available on the class path.
<br><b><font color="#FF0000">Notice</font></b>: that both TestCollectors
assume that the class files reside are kept in the file system. This isn't
case in VA/Java and they will not work there. A custom TestCollector is
Expand Down
12 changes: 6 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- JUnit build script using ant 2.0 -->
<!-- JUnit build script using ant 1.3 -->
<project name="junit" default="dist" basedir=".">
<target name="init">
<tstamp/>
<property name="version" value="3.5" />
<property name="version" value="3.6" />
<property name="dist" value="junit${version}" />
<property name="versionfile" value="junit/runner/Version.java" />
<property name="zipfile" value="${dist}.zip" />
Expand Down Expand Up @@ -32,12 +32,12 @@
<jar
jarfile="${dist}/src.jar"
basedir="."
excludes="junit/tests/**, junit/samples/**, **/*.class, doc/**, README.html, build.xml"
excludes="${dist}/src.jar, junit/tests/**, junit/samples/**, **/*.class, doc/**, README.html, build.xml"
/>
<jar
jarfile="${dist}/junit.jar"
basedir="."
excludes="junit/tests/**, junit/samples/**, **/*.java, doc/**, README.html, jar-manifest.txt"
excludes="${dist}/junit.jar, junit/tests/**, junit/samples/**, **/*.java, doc/**, README.html, jar-manifest.txt"
/>
<copy todir="${dist}/junit/samples">
<fileset dir="junit/samples" />
Expand Down Expand Up @@ -78,9 +78,9 @@
<target name="zip">
<!-- !!! hard code names, variable substitution doesn't work !!! -->
<zip
zipfile="junit3.5.zip"
zipfile="junit3.6.zip"
basedir="."
includes="junit3.5/**"
includes="junit3.6/**"
/>
</target>

Expand Down
2 changes: 1 addition & 1 deletion doc/testinfected/testing.htm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1>
The universal response to "Why not?" is "I'm in too much of a hurry." This
quickly becomes a vicious cycle- the more pressure you feel, the fewer
tests you write. The fewer tests you write, the less productive you are
and the less stable you code becomes. The less productive and accurate
and the less stable your code becomes. The less productive and accurate
you are, the more pressure you feel.
<p>Programmers burn out from just such cycles. Breaking out requires an
outside influence. We found the outside influence we needed in a simple
Expand Down
39 changes: 28 additions & 11 deletions junit/awtui/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class TestRunner extends BaseTestRunner {
protected Button fQuitButton;
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;
Expand Down Expand Up @@ -181,11 +183,13 @@ public void actionPerformed(ActionEvent e) {
}
}
);

boolean useLoader= useReoadingTestSuiteLoader();
fUseLoadingRunner= new Checkbox("Use custom class loader for loading tests", useLoader);

//---- second section
fProgressIndicator= new ProgressBar();

//---- third section
//---- third section
fNumberOfErrors= new Label("0000", Label.RIGHT);
fNumberOfErrors.setText("0");
fNumberOfErrors.setFont(PLAIN_FONT);
Expand Down Expand Up @@ -257,7 +261,7 @@ public void actionPerformed(ActionEvent e) {

addGrid(panel, fSuiteField, 0, 1, 2, GridBagConstraints.HORIZONTAL, 1.0, GridBagConstraints.WEST);
addGrid(panel, fRun, 2, 1, 1, GridBagConstraints.HORIZONTAL, 0.0, GridBagConstraints.CENTER);

addGrid(panel, fUseLoadingRunner, 0, 2, 2, GridBagConstraints.HORIZONTAL, 1.0, GridBagConstraints.WEST);
addGrid(panel, fProgressIndicator, 0, 3, 2, GridBagConstraints.HORIZONTAL, 1.0, GridBagConstraints.WEST);
addGrid(panel, fLogo, 2, 3, 1, GridBagConstraints.NONE, 0.0, GridBagConstraints.NORTH);

Expand Down Expand Up @@ -378,11 +382,14 @@ synchronized public void runSuite() {
if (fRunner != null) {
fTestResult.stop();
} else {
if (!setUseLoadingRunner())
return;
fRun.setLabel("Stop");
showInfo("Initializing...");
reset();

showInfo("Load Test Case...");

final Test testSuite= getTest(fSuiteField.getText());
if (testSuite != null) {
fRunner= new Thread() {
Expand Down Expand Up @@ -413,8 +420,25 @@ 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 void setLabelValue(Label label, int value) {
label.setText(Integer.toString(value));
label.invalidate();
label.getParent().validate();

}

public void setSuiteName(String suite) {
Expand All @@ -427,16 +451,9 @@ private void showErrorTrace() {
return;

Throwable t= (Throwable) fExceptions.elementAt(index);
fTraceArea.setText(filterStack(getTrace(t)));
fTraceArea.setText(getFilteredTrace(t));
}

private String getTrace(Throwable t) {
StringWriter stringWriter= new StringWriter();
PrintWriter writer= new PrintWriter(stringWriter);
t.printStackTrace(writer);
StringBuffer buffer= stringWriter.getBuffer();
return buffer.toString();
}

private void showInfo(String message) {
fStatusLine.setFont(PLAIN_FONT);
Expand Down
80 changes: 80 additions & 0 deletions junit/awtui/WarningDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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;
}
}
2 changes: 1 addition & 1 deletion junit/extensions/TestDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String toString() {
return fTest.toString();
}

protected Test getTest() {
public Test getTest() {
return fTest;
}
}
26 changes: 20 additions & 6 deletions junit/framework/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,41 @@ static public void assertEquals(Object expected, Object actual) {
assertEquals(null, expected, actual);
}
/**
* Asserts that two doubles are equal.
* Asserts that two doubles are equal concerning a delta. If the expected
* value is infinity then the delta value is ignored.
*/
static public void assertEquals(String message, double expected, double actual, double delta) {
if (!(Math.abs(expected-actual) <= delta)) // Because comparison with NaN always returns false
// handle infinity specially since subtracting to infinite values gives NaN and the
// the following test fails
if (Double.isInfinite(expected)) {
if (!Double.isInfinite(actual))
failNotEquals(message, new Double(expected), new Double(actual));
} else if (!(Math.abs(expected-actual) <= delta)) // Because comparison with NaN always returns false
failNotEquals(message, new Double(expected), new Double(actual));
}
/**
* Asserts that two doubles are equal.
* Asserts that two doubles are equal concerning a delta. If the expected
* value is infinity then the delta value is ignored.
*/
static public void assertEquals(double expected, double actual, double delta) {
assertEquals(null, expected, actual, delta);
}
/**
* Asserts that two floats are equal concerning a delta
* Asserts that two floats are equal concerning a delta. If the expected
* value is infinity then the delta value is ignored.
*/
static public void assertEquals(String message, float expected, float actual, float delta) {
if (!(Math.abs(expected-actual) <= delta))
// handle infinity specially since subtracting to infinite values gives NaN and the
// the following test fails
if (Float.isInfinite(expected)) {
if (!Float.isInfinite(actual))
failNotEquals(message, new Float(expected), new Float(actual));
} else if (!(Math.abs(expected-actual) <= delta))
failNotEquals(message, new Float(expected), new Float(actual));
}
/**
* Asserts that two floats are equal concerning a delta
* Asserts that two floats are equal concerning a delta. If the expected
* value is infinity then the delta value is ignored.
*/
static public void assertEquals(float expected, float actual, float delta) {
assertEquals(null, expected, actual, delta);
Expand Down
4 changes: 2 additions & 2 deletions junit/framework/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ protected void runTest() throws Throwable {
// methods. getDeclaredMethods returns all
// methods of this class but excludes the
// inherited ones.
runMethod= getClass().getMethod(fName, new Class[0]);
runMethod= getClass().getMethod(fName, null);
} catch (NoSuchMethodException e) {
fail("Method \""+fName+"\" not found");
}
if (runMethod != null && !Modifier.isPublic(runMethod.getModifiers())) {
if (!Modifier.isPublic(runMethod.getModifiers())) {
fail("Method \""+fName+"\" should be public");
}

Expand Down
Loading

0 comments on commit bfc94ee

Please sign in to comment.