You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(80) |
Nov
(42) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(11) |
Feb
(50) |
Mar
(70) |
Apr
(102) |
May
(28) |
Jun
(45) |
Jul
(14) |
Aug
(75) |
Sep
(17) |
Oct
(15) |
Nov
(11) |
Dec
(4) |
2003 |
Jan
(16) |
Feb
(19) |
Mar
(21) |
Apr
(20) |
May
(29) |
Jun
(7) |
Jul
(5) |
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(3) |
2004 |
Jan
(5) |
Feb
(4) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(1) |
Jul
(7) |
Aug
(1) |
Sep
(6) |
Oct
(6) |
Nov
(1) |
Dec
(2) |
2005 |
Jan
(4) |
Feb
(4) |
Mar
(15) |
Apr
(1) |
May
|
Jun
(4) |
Jul
(6) |
Aug
(6) |
Sep
|
Oct
(4) |
Nov
(2) |
Dec
(4) |
2006 |
Jan
|
Feb
(91) |
Mar
(47) |
Apr
(7) |
May
(4) |
Jun
(9) |
Jul
(1) |
Aug
|
Sep
(5) |
Oct
(36) |
Nov
(95) |
Dec
(12) |
2007 |
Jan
(11) |
Feb
(31) |
Mar
(45) |
Apr
(11) |
May
(9) |
Jun
(1) |
Jul
(146) |
Aug
(15) |
Sep
|
Oct
(3) |
Nov
(6) |
Dec
(1) |
2008 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(3) |
Jul
(2) |
Aug
(19) |
Sep
(1) |
Oct
(10) |
Nov
|
Dec
(8) |
2009 |
Jan
(3) |
Feb
(1) |
Mar
(4) |
Apr
(8) |
May
(5) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
(2) |
Oct
(13) |
Nov
(13) |
Dec
(4) |
2010 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(2) |
May
|
Jun
(1) |
Jul
(3) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2011 |
Jan
(1) |
Feb
(4) |
Mar
(3) |
Apr
(4) |
May
|
Jun
(12) |
Jul
(16) |
Aug
(4) |
Sep
(7) |
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
|
From: David S. <ds...@us...> - 2006-12-13 02:10:57
|
Update of /cvsroot/junit/junit/src/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27005/src/org/junit/tests Modified Files: TimeoutTest.java AllTests.java Log Message: JUnitCore can run a class with a suite() method. Index: TimeoutTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/TimeoutTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TimeoutTest.java 6 Dec 2006 01:22:48 -0000 1.4 +++ TimeoutTest.java 13 Dec 2006 02:10:51 -0000 1.5 @@ -63,7 +63,8 @@ } } - @Ignore("was breaking gump") @Test public void timeoutFailure() throws Exception { + @Ignore("was breaking gump") + @Test public void timeoutFailure() throws Exception { JUnitCore core= new JUnitCore(); Result result= core.run(TimeoutFailureTest.class); assertEquals(1, result.getRunCount()); @@ -100,8 +101,11 @@ } } - + @Ignore("This breaks sporadically with time differences just slightly more than 200ms") @Test public void infiniteLoopRunsForApproximatelyLengthOfTimeout() throws Exception { + // "prime the pump": running these beforehand makes the runtimes more predictable + // (because of class loading?) + JUnitCore.runClasses(InfiniteLoopTest.class, ImpatientLoopTest.class); long longTime= runAndTime(InfiniteLoopTest.class); long shortTime= runAndTime(ImpatientLoopTest.class); long difference= longTime - shortTime; Index: AllTests.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/AllTests.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- AllTests.java 6 Dec 2006 01:22:48 -0000 1.2 +++ AllTests.java 13 Dec 2006 02:10:51 -0000 1.3 @@ -39,7 +39,7 @@ OldTestClassRunnerTest.class, JUnitCoreTest.class, InaccessibleBaseClassTest.class, -// SuiteMethodTest.class, + SuiteMethodTest.class, TestClassMethodsRunnerTest.class }) public class AllTests { |
From: David S. <ds...@us...> - 2006-12-13 02:10:57
|
Update of /cvsroot/junit/junit/src/junit/framework In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27005/src/junit/framework Modified Files: JUnit4TestAdapter.java Log Message: JUnitCore can run a class with a suite() method. Index: JUnit4TestAdapter.java =================================================================== RCS file: /cvsroot/junit/junit/src/junit/framework/JUnit4TestAdapter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- JUnit4TestAdapter.java 21 Nov 2006 18:53:38 -0000 1.1 +++ JUnit4TestAdapter.java 13 Dec 2006 02:10:51 -0000 1.2 @@ -21,7 +21,7 @@ JUnit4TestAdapterCache cache) { fCache = cache; fNewTestClass = newTestClass; - fRunner = Request.aClass(newTestClass).getRunner(); + fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); } public int countTestCases() { |
From: David S. <ds...@us...> - 2006-12-13 02:10:57
|
Update of /cvsroot/junit/junit/src/org/junit/internal/requests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27005/src/org/junit/internal/requests Modified Files: ClassRequest.java Log Message: JUnitCore can run a class with a suite() method. Index: ClassRequest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/internal/requests/ClassRequest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ClassRequest.java 21 Nov 2006 18:53:34 -0000 1.1 +++ ClassRequest.java 13 Dec 2006 02:10:51 -0000 1.2 @@ -7,12 +7,19 @@ import org.junit.runner.Request; import org.junit.runner.RunWith; import org.junit.runner.Runner; +import org.junit.runners.AllTests; public class ClassRequest extends Request { private final Class<?> fTestClass; + private boolean fCanUseSuiteMethod; - public ClassRequest(Class<?> each) { - fTestClass= each; + public ClassRequest(Class<?> testClass, boolean canUseSuiteMethod) { + fTestClass= testClass; + fCanUseSuiteMethod= canUseSuiteMethod; + } + + public ClassRequest(Class<?> testClass) { + this(testClass, true); } @Override @@ -32,6 +39,8 @@ RunWith annotation= testClass.getAnnotation(RunWith.class); if (annotation != null) { return annotation.value(); + } else if (hasSuiteMethod() && fCanUseSuiteMethod) { + return AllTests.class; } else if (isPre4Test(testClass)) { return OldTestClassRunner.class; } else { @@ -39,6 +48,19 @@ } } + private boolean hasSuiteMethod() { + // TODO: check all attributes + try { + fTestClass.getMethod("suite"); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + return false; + } + return true; + } + boolean isPre4Test(Class<?> testClass) { return junit.framework.TestCase.class.isAssignableFrom(testClass); } |
From: David S. <ds...@us...> - 2006-12-13 02:10:56
|
Update of /cvsroot/junit/junit/src/org/junit/runner In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27005/src/org/junit/runner Modified Files: Request.java Log Message: JUnitCore can run a class with a suite() method. Index: Request.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/runner/Request.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Request.java 21 Nov 2006 18:53:39 -0000 1.1 +++ Request.java 13 Dec 2006 02:10:50 -0000 1.2 @@ -111,4 +111,8 @@ public Request sortWith(Comparator<Description> comparator) { return new SortingRequest(this, comparator); } + + public static Request classWithoutSuiteMethod(Class<?> newTestClass) { + return new ClassRequest(newTestClass, false); + } } |
From: David S. <ds...@us...> - 2006-11-30 20:00:26
|
Update of /cvsroot/junit/junit/src/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11061/src/org/junit/tests Modified Files: TimeoutTest.java Log Message: Ignoring the timeout test, so that gump can run. Need to fix this later. Index: TimeoutTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/TimeoutTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TimeoutTest.java 21 Nov 2006 19:52:30 -0000 1.2 +++ TimeoutTest.java 30 Nov 2006 20:00:21 -0000 1.3 @@ -63,7 +63,7 @@ } } - @Test public void timeoutFailure() throws Exception { + @Ignore("was breaking gump") @Test public void timeoutFailure() throws Exception { JUnitCore core= new JUnitCore(); Result result= core.run(TimeoutFailureTest.class); assertEquals(1, result.getRunCount()); |
From: Antoine Levy-L. <an...@gm...> - 2006-11-30 16:36:18
|
Hello David, Unfortunately, there is still a little fishbone in the soup : http://clarus.apache.org/junit/junit/gump_work/build_junit_junit.html Regards, Antoine [java] java.lang.AssertionError: expected:<class java.lang.InterruptedException> but was:<class java.lang.Exception> [java] at org.junit.Assert.fail(Assert.java:69) [java] at org.junit.Assert.failNotEquals(Assert.java:404) [java] at org.junit.Assert.assertEquals(Assert.java:97) [java] at org.junit.Assert.assertEquals(Assert.java:108) [java] at org.junit.tests.TimeoutTest.timeoutFailure(TimeoutTest.java:71) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at java.lang.reflect.Method.invoke(Method.java:585) [java] at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethod http://clarus.apache.org/junit/junit/gump_work/build_junit_junit.html |
From: David S. <sa...@mi...> - 2006-11-30 15:09:56
|
Antoine, Thanks, I've checked in the fix. Eclipse auto-creates the bin directory, so the error was masked. David Saff On 11/30/06, Antoine Levy-Lambert <an...@gm...> wrote: > Hello David, > > I suppose that the build file which is causing trouble in gump is the > one visible under this URL : > > http://junit.cvs.sourceforge.net/junit/junit/build.xml? > hideattic=1&revision=1.19&view=markup > > if you add in the target build in line 28 > <mkdir dir="${bin}"/> the problem will be fixed. > > I have also introduced a workaround in gump, but please do this > change so that we can remove the workaround. > > Regards, > > Antoine > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Junit-devel mailing list > Jun...@li... > https://lists.sourceforge.net/lists/listinfo/junit-devel > |
From: David S. <ds...@us...> - 2006-11-30 15:07:21
|
Update of /cvsroot/junit/junit In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27786 Modified Files: build.xml Log Message: Need to create bin dir in build.xml for users not on Eclipse. Index: build.xml =================================================================== RCS file: /cvsroot/junit/junit/build.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- build.xml 21 Nov 2006 18:53:41 -0000 1.19 +++ build.xml 30 Nov 2006 15:07:16 -0000 1.20 @@ -25,6 +25,7 @@ </target> <target name="build" depends="versiontag"> + <mkdir dir="${bin}"/> <javac srcdir="${src}" destdir="${bin}" |
From: Antoine Levy-L. <an...@gm...> - 2006-11-30 12:45:21
|
Hello David, I suppose that the build file which is causing trouble in gump is the one visible under this URL : http://junit.cvs.sourceforge.net/junit/junit/build.xml? hideattic=1&revision=1.19&view=markup if you add in the target build in line 28 <mkdir dir="${bin}"/> the problem will be fixed. I have also introduced a workaround in gump, but please do this change so that we can remove the workaround. Regards, Antoine |
From: Haricharan R. <har...@ya...> - 2006-11-21 21:28:45
|
Hi All, =0A=0A I am new to JUnit-devel list. and this is my first quetion.= =0A=0AI have a class with a constructor, the constructor takes a file name= as an agriment and assignes it to a instance variable of the type String. = =0A=0AThis file name is later used in another method which when called will= open the file name as in the instance variable.=0A=0AThe class code looks = like this=0A=0Aclass ExClass =0A{=0A=0A private String FILENAME =3D null;= =0A=0A public ExClass(String FILENAME)=0A{=0A this.FILENAME =3D FILENAME= ;=0A}=0A=0A// Other methods ....=0A} =0A =0A=0ACan any one please giv= e suggestions to test this constructor.=0A=0A What I have right now is a = test case which trys to instantiate this class and verifies that an Object = is created. =0AI can think of the following cases. =0A=0A ExClass ExObj= =3D new ExClass("somefile.txt");=0A assertNotNull(ExObj);=0A=0A = [OR] =0A boolean flah =3D false;=0A try{=0A=0A = ExClass ExObj =3D new ExClass("somefile.txt");=0A }=0A catch (E= xception e) { flag =3D true; }=0A assertFalse(flag);=0A=0Athanks=0AHari= =0A=0A=0A =0A______________________________________________________________= ______________________=0ASponsored Link=0A=0ARates near 39yr lows. $420,000= Loan for $1399/mo. =0ACalcuate new payment. www.LowerMyBills.com/lre=0A |
From: David S. <ds...@us...> - 2006-11-21 19:52:34
|
Update of /cvsroot/junit/junit/src/org/junit In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11520/src/org/junit Modified Files: Assert.java Log Message: Fixed two bugs: RunWtih(Suite) should not require a default constructor Test(timeout) was taking twice as long as specified Index: Assert.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/Assert.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Assert.java 21 Nov 2006 18:53:34 -0000 1.1 +++ Assert.java 21 Nov 2006 19:52:30 -0000 1.2 @@ -160,6 +160,81 @@ } /** + * Asserts that two longs are equal. If they are not + * an {@link AssertionError} is thrown with the given message. + */ + static public void assertEquals(String message, long expected, long actual) { + assertEquals(message, Long.valueOf(expected), Long.valueOf(actual)); + } + + /** + * Asserts that two longs are equal. + */ + static public void assertEquals(long expected, long actual) { + assertEquals(null, expected, actual); + } + + /** + * Asserts that two bytes are equal. If they are not + * an {@link AssertionError} is thrown with the given message. + */ + static public void assertEquals(String message, byte expected, byte actual) { + assertEquals(message, Byte.valueOf(expected), Byte.valueOf(actual)); + } + + /** + * Asserts that two bytes are equal. + */ + static public void assertEquals(byte expected, byte actual) { + assertEquals(null, expected, actual); + } + + /** + * Asserts that two chars are equal. If they are not + * an {@link AssertionError} is thrown with the given message. + */ + static public void assertEquals(String message, char expected, char actual) { + assertEquals(message, Character.valueOf(expected), Character.valueOf(actual)); + } + + /** + * Asserts that two chars are equal. + */ + static public void assertEquals(char expected, char actual) { + assertEquals(null, expected, actual); + } + + /** + * Asserts that two shorts are equal. If they are not + * an {@link AssertionError} is thrown with the given message. + */ + static public void assertEquals(String message, short expected, short actual) { + assertEquals(message, Short.valueOf(expected), Short.valueOf(actual)); + } + + /** + * Asserts that two shorts are equal. + */ + static public void assertEquals(short expected, short actual) { + assertEquals(null, expected, actual); + } + + /** + * Asserts that two ints are equal. If they are not + * an {@link AssertionError} is thrown with the given message. + */ + static public void assertEquals(String message, int expected, int actual) { + assertEquals(message, Integer.valueOf(expected), Integer.valueOf(actual)); + } + + /** + * Asserts that two ints are equal. + */ + static public void assertEquals(int expected, int actual) { + assertEquals(null, expected, actual); + } + + /** * Asserts that two doubles are equal to within a positive delta. If they * are not, an {@link AssertionError} is thrown with the given message. If the * expected value is infinity then the delta value is ignored. NaNs are |
From: David S. <ds...@us...> - 2006-11-21 19:52:34
|
Update of /cvsroot/junit/junit/src/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11520/src/org/junit/tests Modified Files: SuiteTest.java AssertionTest.java TimeoutTest.java Log Message: Fixed two bugs: RunWtih(Suite) should not require a default constructor Test(timeout) was taking twice as long as specified Index: SuiteTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/SuiteTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SuiteTest.java 21 Nov 2006 18:53:34 -0000 1.1 +++ SuiteTest.java 21 Nov 2006 19:52:30 -0000 1.2 @@ -1,6 +1,6 @@ package org.junit.tests; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.util.List; @@ -128,6 +128,20 @@ assertEquals(2, result.getFailureCount()); } + @RunWith(Suite.class) + @SuiteClasses( {}) + public class WithoutDefaultConstructor { + public WithoutDefaultConstructor(int i) { + + } + } + + @Test + public void suiteShouldBeOKwithNonDefaultConstructor() throws Exception { + Result result= JUnitCore.runClasses(WithoutDefaultConstructor.class); + assertTrue(result.wasSuccessful()); + } + public static junit.framework.Test suite() { return new JUnit4TestAdapter(SuiteTest.class); } Index: AssertionTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/AssertionTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- AssertionTest.java 21 Nov 2006 18:53:34 -0000 1.1 +++ AssertionTest.java 21 Nov 2006 19:52:30 -0000 1.2 @@ -297,6 +297,23 @@ assertEquals(a1, a2); } + @Test public void implicitTypecastEquality() { + byte b = 1; + short s = 1; + int i = 1; + long l = 1L; + float f = 1.0f; + double d = 1.0; + + assertEquals(b, s); + assertEquals(b, i); + assertEquals(b, l); + assertEquals(s, i); + assertEquals(s, l); + assertEquals(i, l); + assertEquals(f, d, 0); + } + static public junit.framework.Test suite() { return new JUnit4TestAdapter(AssertionTest.class); } Index: TimeoutTest.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/tests/TimeoutTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- TimeoutTest.java 21 Nov 2006 18:53:34 -0000 1.1 +++ TimeoutTest.java 21 Nov 2006 19:52:30 -0000 1.2 @@ -89,6 +89,32 @@ Throwable exception= result.getFailures().get(0).getException(); assertTrue(exception.getMessage().contains("test timed out after 100 milliseconds")); } + + static public class ImpatientLoopTest { + @Test(timeout= 1) public void failure() { + infiniteLoop(); + } + + private void infiniteLoop() { + for(;;); + } + } + + + @Test public void infiniteLoopRunsForApproximatelyLengthOfTimeout() throws Exception { + long longTime= runAndTime(InfiniteLoopTest.class); + long shortTime= runAndTime(ImpatientLoopTest.class); + long difference= longTime - shortTime; + assertTrue(String.format("Difference was %sms", difference), difference < 200); + } + + private long runAndTime(Class<?> clazz) { + JUnitCore core= new JUnitCore(); + long startTime= System.currentTimeMillis(); + core.run(clazz); + long totalTime = System.currentTimeMillis() - startTime; + return totalTime; + } @Ignore("We would like this behavior to work but it may not be possible") @Test public void stalledThreadAppearsInStackTrace() throws Exception { |
From: David S. <ds...@us...> - 2006-11-21 19:52:34
|
Update of /cvsroot/junit/junit In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11520 Modified Files: acknowledgements.txt Log Message: Fixed two bugs: RunWtih(Suite) should not require a default constructor Test(timeout) was taking twice as long as specified Index: acknowledgements.txt =================================================================== RCS file: /cvsroot/junit/junit/acknowledgements.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- acknowledgements.txt 3 Aug 2006 22:03:01 -0000 1.2 +++ acknowledgements.txt 21 Nov 2006 19:52:30 -0000 1.3 @@ -3,4 +3,8 @@ 2006 August 3 giovanni: better test for TestCase without a name. - Matthias Pfau: better error message when test case constructor fails \ No newline at end of file + Matthias Pfau: better error message when test case constructor fails + +2006 November 21 + dakcalouro: Found bug with comparing ints and longs (1555161) + Ben Maurer: Found bug with timeouts taking twice as long as specified (1536198) \ No newline at end of file |
From: David S. <ds...@us...> - 2006-11-21 19:52:33
|
Update of /cvsroot/junit/junit/src/org/junit/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11520/src/org/junit/runners Modified Files: Suite.java Log Message: Fixed two bugs: RunWtih(Suite) should not require a default constructor Test(timeout) was taking twice as long as specified Index: Suite.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/runners/Suite.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Suite.java 21 Nov 2006 18:53:41 -0000 1.1 +++ Suite.java 21 Nov 2006 19:52:30 -0000 1.2 @@ -8,6 +8,7 @@ import java.util.Set; import org.junit.internal.runners.InitializationError; +import org.junit.internal.runners.MethodValidator; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.Request; @@ -57,4 +58,10 @@ throw new InitializationError(String.format("class '%s' must have a SuiteClasses annotation", klass.getName())); return annotation.value(); } + + @Override + protected void validate(MethodValidator methodValidator) { + methodValidator.validateStaticMethods(); + methodValidator.validateInstanceMethods(); + } } |
From: David S. <ds...@us...> - 2006-11-21 19:52:33
|
Update of /cvsroot/junit/junit/src/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11520/src/org/junit/internal/runners Modified Files: TestMethodRunner.java Log Message: Fixed two bugs: RunWtih(Suite) should not require a default constructor Test(timeout) was taking twice as long as specified Index: TestMethodRunner.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/internal/runners/TestMethodRunner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- TestMethodRunner.java 21 Nov 2006 18:53:34 -0000 1.1 +++ TestMethodRunner.java 21 Nov 2006 19:52:30 -0000 1.2 @@ -63,7 +63,7 @@ TimeUnit.MILLISECONDS); if (!terminated) service.shutdownNow(); - result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation + result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation } catch (TimeoutException e) { addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout))); } catch (Exception e) { |
Update of /cvsroot/junit/junit/src/org/junit/runner In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/src/org/junit/runner Added Files: Request.java package-info.java Runner.java Result.java JUnitCore.java RunWith.java Description.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- NEW FILE: Request.java --- package org.junit.runner; import java.util.Comparator; import org.junit.internal.requests.ClassRequest; import org.junit.internal.requests.ClassesRequest; import org.junit.internal.requests.ErrorReportingRequest; import org.junit.internal.requests.FilterRequest; import org.junit.internal.requests.SortingRequest; import org.junit.runner.manipulation.Filter; /** * <p>A <code>Request</code> is an abstract description of tests to be run. Older versions of * JUnit did not need such a concept--tests to be run were described either by classes containing * tests or a tree of {@link org.junit.Test}s. However, we want to support filtering and sorting, * so we need a more abstract specification than the tests themselves and a richer * specification than just the classes.</p> * * <p>The flow when JUnit runs tests is that a <code>Request</code> specifies some tests to be run -> * a {@link org.junit.runner.Runner} is created for each class implied by the <code>Request</code> -> * the {@link org.junit.runner.Runner} returns a detailed {@link org.junit.runner.Description} * which is a tree structure of the tests to be run.</p> */ public abstract class Request { /** * Create a <code>Request</code> that, when processed, will run a single test. * This is done by filtering out all other tests. This method is used to support rerunning * single tests. * @param clazz the class of the test * @param methodName the name of the test * @return a <code>Request</code> that will cause a single test be run */ public static Request method(Class<?> clazz, String methodName) { Description method= Description.createTestDescription(clazz, methodName); return Request.aClass(clazz).filterWith(method); } /** * Create a <code>Request</code> that, when processed, will run all the tests * in a class. The odd name is necessary because <code>class</code> is a reserved word. * @param clazz the class containing the tests * @return a <code>Request</code> that will cause all tests in the class to be run */ public static Request aClass(Class<?> clazz) { return new ClassRequest(clazz); } /** * Create a <code>Request</code> that, when processed, will run all the tests * in a set of classes. * @param collectionName a name to identify this suite of tests * @param classes the classes containing the tests * @return a <code>Request</code> that will cause all tests in the classes to be run */ public static Request classes(String collectionName, Class<?>... classes) { return new ClassesRequest(collectionName, classes); } public static Request errorReport(Class<?> klass, Throwable cause) { return new ErrorReportingRequest(klass, cause); } /** * Returns a {@link Runner} for this Request * @return corresponding {@link Runner} for this Request */ public abstract Runner getRunner(); /** * Returns a Request that only contains those tests that should run when * <code>filter</code> is applied * @param filter The {@link Filter} to apply to this Request * @return the filtered Request */ public Request filterWith(Filter filter) { return new FilterRequest(this, filter); } /** * Returns a Request that only runs contains tests whose {@link Description} * equals <code>desiredDescription</code> * @param desiredDescription {@link Description} of those tests that should be run * @return the filtered Request */ public Request filterWith(final Description desiredDescription) { return filterWith(new Filter() { @Override public boolean shouldRun(Description description) { // TODO: test for equality even if we have children? if (description.isTest()) return desiredDescription.equals(description); for (Description each : description.getChildren()) if (shouldRun(each)) return true; return false; } @Override public String describe() { return String.format("Method %s", desiredDescription.getDisplayName()); } }); } /** * Returns a Request whose Tests can be run in a certain order, defined by * <code>comparator</code> * @param comparator definition of the order of the tests in this Request * @return a Request with ordered Tests */ public Request sortWith(Comparator<Description> comparator) { return new SortingRequest(this, comparator); } } --- NEW FILE: package-info.java --- /** * Provides classes used to describe, collect, run and analyze multiple tests. * * @since 4.0 */ package org.junit.runner; --- NEW FILE: Runner.java --- package org.junit.runner; import org.junit.runner.notification.RunNotifier; /** * A <code>Runner</code> runs tests and notifies a {@link org.junit.runner.notification.RunNotifier} * of significant events as it does so. You will need to subclass <code>Runner</code> * when using {@link org.junit.runner.RunWith} to invoke a custom runner. When creating * a custom runner, in addition to implementing the abstract methods here you must * also provide a constructor that takes as an argument the {@link Class} containing * the tests. * <p/> * The default runner implementation guarantees that the instances of the test case * class will be constructed immediately before running the test and that the runner * will retain no reference to the test case instances, generally making them * available for garbage collection. * * @see org.junit.runner.Description * @see org.junit.runner.RunWith */ public abstract class Runner { /** * @return a {@link Description} showing the tests to be run by the receiver */ public abstract Description getDescription(); /** * Run the tests for this runner. * @param notifier will be notified of events while tests are being run--tests being * started, finishing, and failing */ public abstract void run(RunNotifier notifier); /** * @return the number of tests to be run by the receiver */ public int testCount() { return getDescription().testCount(); } } --- NEW FILE: Result.java --- package org.junit.runner; import java.util.ArrayList; import java.util.List; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; /** * A <code>Result</code> collects and summarizes information from running multiple * tests. Since tests are expected to run correctly, successful tests are only noted in * the count of tests that ran. */ public class Result { private int fCount= 0; private int fIgnoreCount= 0; private List<Failure> fFailures= new ArrayList<Failure>(); private long fRunTime= 0; private long fStartTime; /** * @return the number of tests run */ public int getRunCount() { return fCount; } /** * @return the number of tests that failed during the run */ public int getFailureCount() { return fFailures.size(); } /** * @return the number of milliseconds it took to run the entire suite to run */ public long getRunTime() { return fRunTime; } /** * @return the {@link Failure}s describing tests that failed and the problems they encountered */ public List<Failure> getFailures() { return fFailures; } /** * @return the number of tests ignored during the run */ public int getIgnoreCount() { return fIgnoreCount; } /** * @return <code>true</code> if all tests succeeded */ public boolean wasSuccessful() { return getFailureCount() == 0; } private class Listener extends RunListener { @Override public void testRunStarted(Description description) throws Exception { fStartTime= System.currentTimeMillis(); } @Override public void testRunFinished(Result result) throws Exception { long endTime= System.currentTimeMillis(); fRunTime+= endTime - fStartTime; } @Override public void testStarted(Description description) throws Exception { fCount++; } @Override public void testFailure(Failure failure) throws Exception { fFailures.add(failure); } @Override public void testIgnored(Description description) throws Exception { fIgnoreCount++; } } /** * Internal use only. */ public RunListener createListener() { return new Listener(); } } --- NEW FILE: JUnitCore.java --- package org.junit.runner; import java.util.ArrayList; import java.util.List; import junit.runner.Version; import org.junit.internal.runners.OldTestClassRunner; import org.junit.internal.runners.TextListener; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; import org.junit.runner.notification.RunNotifier; /** * <code>JUnitCore</code> is a facade for running tests. It supports running JUnit 4 tests, * JUnit 3.8.x tests, and mixtures. To run tests from the command line, run * <code>java org.junit.runner.JUnitCore TestClass1 TestClass2 ...</code>. * For one-shot test runs, use the static method {@link #runClasses(Class[])}. * If you want to add special listeners, * create an instance of {@link org.junit.runner.JUnitCore} first and use it to run the tests. * * @see org.junit.runner.Result * @see org.junit.runner.notification.RunListener * @see org.junit.runner.Request */ public class JUnitCore { private RunNotifier fNotifier; /** * Create a new <code>JUnitCore</code> to run tests. */ public JUnitCore() { fNotifier= new RunNotifier(); } /** * Run the tests contained in the classes named in the <code>args</code>. * If all tests run successfully, exit with a status of 0. Otherwise exit with a status of 1. * Write feedback while tests are running and write * stack traces for all failed tests after the tests all complete. * @param args names of classes in which to find tests to run */ public static void main(String... args) { Result result= new JUnitCore().runMain(args); killAllThreads(result); } private static void killAllThreads(Result result) { System.exit(result.wasSuccessful() ? 0 : 1); } /** * Run the tests contained in <code>classes</code>. Write feedback while the tests * are running and write stack traces for all failed tests after all tests complete. This is * similar to {@link #main(String[])}, but intended to be used programmatically. * @param classes Classes in which to find tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public static Result runClasses(Class<?>... classes) { return new JUnitCore().run(classes); } /** * Do not use. Testing purposes only. */ public Result runMain(String... args) { System.out.println("JUnit version " + Version.id()); List<Class<?>> classes= new ArrayList<Class<?>>(); List<Failure> missingClasses= new ArrayList<Failure>(); for (String each : args) try { classes.add(Class.forName(each)); } catch (ClassNotFoundException e) { System.out.println("Could not find class: " + each); Description description= Description.createSuiteDescription(each); Failure failure= new Failure(description, e); missingClasses.add(failure); } RunListener listener= new TextListener(); addListener(listener); Result result= run(classes.toArray(new Class[0])); for (Failure each : missingClasses) result.getFailures().add(each); return result; } /** * @return the version number of this release */ public String getVersion() { return Version.id(); } /** * Run all the tests in <code>classes</code>. * @param classes the classes containing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Class<?>... classes) { return run(Request.classes("All", classes)); } /** * Run all the tests contained in <code>request</code>. * @param request the request describing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request) { return run(request.getRunner()); } /** * Run all the tests contained in JUnit 3.8.x <code>test</code>. Here for backward compatibility. * @param test the old-style test * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(junit.framework.Test test) { return run(new OldTestClassRunner(test)); } /** * Do not use. Testing purposes only. */ public Result run(Runner runner) { Result result= new Result(); RunListener listener= result.createListener(); addFirstListener(listener); try { fNotifier.fireTestRunStarted(runner.getDescription()); runner.run(fNotifier); fNotifier.fireTestRunFinished(result); } finally { removeListener(listener); } return result; } private void addFirstListener(RunListener listener) { fNotifier.addFirstListener(listener); } /** * Add a listener to be notified as the tests run. * @param listener the listener to add * @see org.junit.runner.notification.RunListener */ public void addListener(RunListener listener) { fNotifier.addListener(listener); } /** * Remove a listener. * @param listener the listener to remove */ public void removeListener(RunListener listener) { fNotifier.removeListener(listener); } } --- NEW FILE: RunWith.java --- package org.junit.runner; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; //TODO add simple example /** * When a class is annotated with <code>@RunWith</code> or extends a class annotated * with <code>@RunWith</code>, JUnit will invoke the class it references to run the * tests in that class instead of the runner built into JUnit. We added this feature late * in development. While it seems powerful we expect the runner API to change as we learn * how people really use it. Some of the classes that are currently internal will likely * be refined and become public. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Inherited public @interface RunWith { /** * @return a Runner class (must have a constructor that takes a single Class to run) */ Class<? extends Runner> value(); } --- NEW FILE: Description.java --- package org.junit.runner; import java.util.ArrayList; /** * <p>A <code>Description</code> describes a test which is to be run or has been run. <code>Descriptions</code> * can be atomic (a single test) or compound (containing children tests). <code>Descriptions</code> are used * to provide feedback about the tests that are about to run (for example, the tree view * visible in many IDEs) or tests that have been run (for example, the failures view).</p> * * <p><code>Descriptions</code> are implemented as a single class rather than a Composite because * they are entirely informational. They contain no logic aside from counting their tests.</p> * * <p>In the past, we used the raw {@link junit.framework.TestCase}s and {@link junit.framework.TestSuite}s * to display the tree of tests. This was no longer viable in JUnit 4 because atomic tests no longer have * a superclass below {@link Object}. We needed a way to pass a class and name together. Description * emerged from this.</p> * * @see org.junit.runner.Request * @see org.junit.runner.Runner */ public class Description { /** * Create a <code>Description</code> named <code>name</code>. * Generally, you will add children to this <code>Description</code>. * @param name the name of the <code>Description</code> * @return a <code>Description</code> named <code>name</code> */ public static Description createSuiteDescription(String name) { return new Description(name); } /** * Create a <code>Description</code> of a single test named <code>name</code> in the class <code>clazz</code>. * Generally, this will be a leaf <code>Description</code>. * @param clazz the class of the test * @param name the name of the test (a method name for test annotated with {@link org.junit.Test}) * @return a <code>Description</code> named <code>name</code> */ public static Description createTestDescription(Class<?> clazz, String name) { return new Description(String.format("%s(%s)", name, clazz.getName())); } /** * Create a generic <code>Description</code> that says there are tests in <code>testClass</code>. * This is used as a last resort when you cannot precisely describe the individual tests in the class. * @param testClass A {@link Class} containing tests * @return a <code>Description</code> of <code>testClass</code> */ public static Description createSuiteDescription(Class<?> testClass) { return new Description(testClass.getName()); } public static Description TEST_MECHANISM = new Description("Test mechanism"); private final ArrayList<Description> fChildren= new ArrayList<Description>(); private final String fDisplayName; //TODO we seem to be using the static factories exclusively protected Description(final String displayName) { fDisplayName= displayName; } /** * @return a user-understandable label */ public String getDisplayName() { return fDisplayName; } /** * Add <code>Description</code> as a child of the receiver. * @param description the soon-to-be child. */ public void addChild(Description description) { getChildren().add(description); } /** * @return the receiver's children, if any */ public ArrayList<Description> getChildren() { return fChildren; } /** * @return <code>true</code> if the receiver is a suite */ public boolean isSuite() { return !isTest(); } /** * @return <code>true</code> if the receiver is an atomic test */ public boolean isTest() { return getChildren().isEmpty(); } /** * @return the total number of atomic tests in the receiver */ public int testCount() { if (isTest()) return 1; int result= 0; for (Description child : getChildren()) result+= child.testCount(); return result; } @Override public int hashCode() { return getDisplayName().hashCode(); } @Override public boolean equals(Object obj) { if (!(obj instanceof Description)) return false; Description d = (Description) obj; return getDisplayName().equals(d.getDisplayName()) && getChildren().equals(d.getChildren()); } @Override public String toString() { return getDisplayName(); } } |
Update of /cvsroot/junit/junit/src/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/src/org/junit/internal/runners Added Files: TestClassRunner.java ErrorReportingRunner.java TextListener.java CompositeRunner.java TestIntrospector.java MethodValidator.java TestClassMethodsRunner.java TestMethodRunner.java OldTestClassRunner.java package-info.java InitializationError.java EmptyDescription.java BeforeAndAfterRunner.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- NEW FILE: TestClassRunner.java --- package org.junit.internal.runners; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.Filterable; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sortable; import org.junit.runner.manipulation.Sorter; import org.junit.runner.notification.RunNotifier; import org.junit.runner.notification.Failure; public class TestClassRunner extends Runner implements Filterable, Sortable { protected final Runner fEnclosedRunner; private final Class<?> fTestClass; public TestClassRunner(Class<?> klass) throws InitializationError { this(klass, new TestClassMethodsRunner(klass)); } public TestClassRunner(Class<?> klass, Runner runner) throws InitializationError { fTestClass= klass; fEnclosedRunner= runner; MethodValidator methodValidator= new MethodValidator(klass); validate(methodValidator); methodValidator.assertValid(); } // TODO: this is parallel to passed-in runner protected void validate(MethodValidator methodValidator) { methodValidator.validateAllMethods(); } @Override public void run(final RunNotifier notifier) { BeforeAndAfterRunner runner = new BeforeAndAfterRunner(getTestClass(), BeforeClass.class, AfterClass.class, null) { @Override protected void runUnprotected() { fEnclosedRunner.run(notifier); } // TODO: looks very similar to other method of BeforeAfter, now @Override protected void addFailure(Throwable targetException) { notifier.fireTestFailure(new Failure(getDescription(), targetException)); } }; runner.runProtected(); } @Override public Description getDescription() { return fEnclosedRunner.getDescription(); } // TODO: good behavior when createTest fails // TODO: dup? public void filter(Filter filter) throws NoTestsRemainException { filter.apply(fEnclosedRunner); } public void sort(Sorter sorter) { sorter.apply(fEnclosedRunner); } protected Class<?> getTestClass() { return fTestClass; } } --- NEW FILE: ErrorReportingRunner.java --- package org.junit.internal.runners; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.notification.RunNotifier; import org.junit.runner.notification.Failure; public class ErrorReportingRunner extends Runner { private final Description fDescription; private final Throwable fCause; public ErrorReportingRunner(Description description, Throwable cause) { fDescription= description; fCause= cause; } @Override public Description getDescription() { return fDescription; } // TODO: this is duplicated in TestClassMethodsRunner @Override public void run(RunNotifier notifier) { notifier.fireTestStarted(fDescription); notifier.fireTestFailure(new Failure(fDescription, fCause)); notifier.fireTestFinished(fDescription); } } --- NEW FILE: TextListener.java --- package org.junit.internal.runners; import java.io.PrintStream; import java.text.NumberFormat; import org.junit.runner.Description; import org.junit.runner.Result; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; public class TextListener extends RunListener { private final PrintStream fWriter; public TextListener() { this(System.out); } public TextListener(PrintStream writer) { this.fWriter= writer; } @Override public void testRunFinished(Result result) { printHeader(result.getRunTime()); printFailures(result); printFooter(result); } @Override public void testStarted(Description description) { fWriter.append('.'); } @Override public void testFailure(Failure failure) { fWriter.append('E'); } @Override public void testIgnored(Description description) { fWriter.append('I'); } /* * Internal methods */ private PrintStream getWriter() { return fWriter; } protected void printHeader(long runTime) { getWriter().println(); getWriter().println("Time: " + elapsedTimeAsString(runTime)); } protected void printFailures(Result result) { if (result.getFailureCount() == 0) return; if (result.getFailureCount() == 1) getWriter().println("There was " + result.getFailureCount() + " failure:"); else getWriter().println("There were " + result.getFailureCount() + " failures:"); int i= 1; for (Failure each : result.getFailures()) printFailure(each, i++); } protected void printFailure(Failure failure, int count) { printFailureHeader(failure, count); printFailureTrace(failure); } protected void printFailureHeader(Failure failure, int count) { getWriter().println(count + ") " + failure.getTestHeader()); } protected void printFailureTrace(Failure failure) { getWriter().print(failure.getTrace()); } protected void printFooter(Result result) { if (result.wasSuccessful()) { getWriter().println(); getWriter().print("OK"); getWriter().println(" (" + result.getRunCount() + " test" + (result.getRunCount() == 1 ? "" : "s") + ")"); } else { getWriter().println(); getWriter().println("FAILURES!!!"); getWriter().println("Tests run: " + result.getRunCount() + ", Failures: " + result.getFailureCount()); } getWriter().println(); } /** * Returns the formatted string of the elapsed time. Duplicated from * BaseTestRunner. Fix it. */ protected String elapsedTimeAsString(long runTime) { return NumberFormat.getInstance().format((double) runTime / 1000); } } --- NEW FILE: CompositeRunner.java --- package org.junit.internal.runners; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.Filterable; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sortable; import org.junit.runner.manipulation.Sorter; import org.junit.runner.notification.RunNotifier; public class CompositeRunner extends Runner implements Filterable, Sortable { private final List<Runner> fRunners= new ArrayList<Runner>(); private final String fName; public CompositeRunner(String name) { fName= name; } @Override public void run(RunNotifier notifier) { for (Runner each : fRunners) each.run(notifier); } @Override public Description getDescription() { Description spec= Description.createSuiteDescription(fName); for (Runner runner : fRunners) { spec.addChild(runner.getDescription()); } return spec; } public List<Runner> getRunners() { return fRunners; } public void addAll(List<? extends Runner> runners) { fRunners.addAll(runners); } public void add(Runner runner) { fRunners.add(runner); } public void filter(Filter filter) throws NoTestsRemainException { for (Iterator<Runner> iter= fRunners.iterator(); iter.hasNext();) { Runner runner= iter.next(); if (filter.shouldRun(runner.getDescription())) { filter.apply(runner); } else { iter.remove(); } } } protected String getName() { return fName; } public void sort(final Sorter sorter) { Collections.sort(fRunners, new Comparator<Runner>() { public int compare(Runner o1, Runner o2) { return sorter.compare(o1.getDescription(), o2.getDescription()); } }); for (Runner each : fRunners) { sorter.apply(each); } } } --- NEW FILE: TestIntrospector.java --- package org.junit.internal.runners; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.junit.Test.None; public class TestIntrospector { private final Class< ?> fTestClass; public TestIntrospector(Class<?> testClass) { fTestClass= testClass; } public List<Method> getTestMethods(Class<? extends Annotation> annotationClass) { List<Method> results= new ArrayList<Method>(); for (Class<?> eachClass : getSuperClasses(fTestClass)) { Method[] methods= eachClass.getDeclaredMethods(); for (Method eachMethod : methods) { Annotation annotation= eachMethod.getAnnotation(annotationClass); if (annotation != null && ! isShadowed(eachMethod, results)) results.add(eachMethod); } } if (runsTopToBottom(annotationClass)) Collections.reverse(results); return results; } public boolean isIgnored(Method eachMethod) { return eachMethod.getAnnotation(Ignore.class) != null; } private boolean runsTopToBottom(Class< ? extends Annotation> annotation) { return annotation.equals(Before.class) || annotation.equals(BeforeClass.class); } private boolean isShadowed(Method method, List<Method> results) { for (Method each : results) { if (isShadowed(method, each)) return true; } return false; } private boolean isShadowed(Method current, Method previous) { if (! previous.getName().equals(current.getName())) return false; if (previous.getParameterTypes().length != current.getParameterTypes().length) return false; for (int i= 0; i < previous.getParameterTypes().length; i++) { if (! previous.getParameterTypes()[i].equals(current.getParameterTypes()[i])) return false; } return true; } private List<Class<?>> getSuperClasses(Class< ?> testClass) { ArrayList<Class<?>> results= new ArrayList<Class<?>>(); Class<?> current= testClass; while (current != null) { results.add(current); current= current.getSuperclass(); } return results; } long getTimeout(Method method) { Test annotation= method.getAnnotation(Test.class); long timeout= annotation.timeout(); return timeout; } Class<? extends Throwable> expectedException(Method method) { Test annotation= method.getAnnotation(Test.class); if (annotation.expected() == None.class) return null; else return annotation.expected(); } } --- NEW FILE: MethodValidator.java --- package org.junit.internal.runners; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class MethodValidator { private final TestIntrospector fIntrospector; private final List<Throwable> fErrors= new ArrayList<Throwable>(); private final Class<?> fTestClass; public MethodValidator(Class<?> testClass) { fTestClass= testClass; fIntrospector= new TestIntrospector(testClass); } public void validateInstanceMethods() { validateTestMethods(After.class, false); validateTestMethods(Before.class, false); validateTestMethods(Test.class, false); } public void validateStaticMethods() { validateTestMethods(BeforeClass.class, true); validateTestMethods(AfterClass.class, true); } // TODO Ugly API--one method should do both public List<Throwable> validateAllMethods() { validateNoArgConstructor(); validateStaticMethods(); validateInstanceMethods(); return fErrors; } public void assertValid() throws InitializationError { if (!fErrors.isEmpty()) throw new InitializationError(fErrors); } public void validateNoArgConstructor() { try { fTestClass.getConstructor(); } catch (Exception e) { fErrors.add(new Exception("Test class should have public zero-argument constructor", e)); } } private void validateTestMethods(Class<? extends Annotation> annotation, boolean isStatic) { List<Method> methods= fIntrospector.getTestMethods(annotation); for (Method each : methods) { if (Modifier.isStatic(each.getModifiers()) != isStatic) { String state= isStatic ? "should" : "should not"; fErrors.add(new Exception("Method " + each.getName() + "() " + state + " be static")); } if (!Modifier.isPublic(each.getDeclaringClass().getModifiers())) fErrors.add(new Exception("Class " + each.getDeclaringClass().getName() + " should be public")); if (!Modifier.isPublic(each.getModifiers())) fErrors.add(new Exception("Method " + each.getName() + " should be public")); if (each.getReturnType() != Void.TYPE) fErrors.add(new Exception("Method " + each.getName() + " should be void")); if (each.getParameterTypes().length != 0) fErrors.add(new Exception("Method " + each.getName() + " should have no parameters")); } } } --- NEW FILE: TestClassMethodsRunner.java --- package org.junit.internal.runners; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import org.junit.Test; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.Filterable; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sortable; import org.junit.runner.manipulation.Sorter; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public class TestClassMethodsRunner extends Runner implements Filterable, Sortable { private final List<Method> fTestMethods; private final Class<?> fTestClass; // This assumes that some containing runner will perform validation of the test methods public TestClassMethodsRunner(Class<?> klass) { fTestClass= klass; fTestMethods= new TestIntrospector(getTestClass()).getTestMethods(Test.class); } @Override public void run(RunNotifier notifier) { if (fTestMethods.isEmpty()) testAborted(notifier, getDescription(), new Exception("No runnable methods")); for (Method method : fTestMethods) invokeTestMethod(method, notifier); } private void testAborted(RunNotifier notifier, Description description, Throwable cause) { // TODO: duped! // TODO: envious notifier.fireTestStarted(description); notifier.fireTestFailure(new Failure(description, cause)); notifier.fireTestFinished(description); } @Override public Description getDescription() { Description spec= Description.createSuiteDescription(getName()); List<Method> testMethods= fTestMethods; for (Method method : testMethods) spec.addChild(methodDescription(method)); return spec; } protected String getName() { return getTestClass().getName(); } protected Object createTest() throws Exception { return getTestClass().getConstructor().newInstance(); } protected void invokeTestMethod(Method method, RunNotifier notifier) { Object test; try { test= createTest(); } catch (InvocationTargetException e) { testAborted(notifier, methodDescription(method), e.getCause()); return; } catch (Exception e) { testAborted(notifier, methodDescription(method), e); return; } createMethodRunner(test, method, notifier).run(); } protected TestMethodRunner createMethodRunner(Object test, Method method, RunNotifier notifier) { return new TestMethodRunner(test, method, notifier, methodDescription(method)); } protected String testName(Method method) { return method.getName(); } protected Description methodDescription(Method method) { return Description.createTestDescription(getTestClass(), testName(method)); } public void filter(Filter filter) throws NoTestsRemainException { for (Iterator<Method> iter= fTestMethods.iterator(); iter.hasNext();) { Method method= iter.next(); if (!filter.shouldRun(methodDescription(method))) iter.remove(); } if (fTestMethods.isEmpty()) throw new NoTestsRemainException(); } public void sort(final Sorter sorter) { Collections.sort(fTestMethods, new Comparator<Method>() { public int compare(Method o1, Method o2) { return sorter.compare(methodDescription(o1), methodDescription(o2)); } }); } protected Class<?> getTestClass() { return fTestClass; } } --- NEW FILE: TestMethodRunner.java --- package org.junit.internal.runners; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; import org.junit.runner.notification.Failure; public class TestMethodRunner extends BeforeAndAfterRunner { private final Object fTest; private final Method fMethod; private final RunNotifier fNotifier; private final TestIntrospector fTestIntrospector; private final Description fDescription; public TestMethodRunner(Object test, Method method, RunNotifier notifier, Description description) { super(test.getClass(), Before.class, After.class, test); fTest= test; fMethod= method; fNotifier= notifier; fTestIntrospector= new TestIntrospector(test.getClass()); fDescription= description; } public void run() { if (fTestIntrospector.isIgnored(fMethod)) { fNotifier.fireTestIgnored(fDescription); return; } fNotifier.fireTestStarted(fDescription); try { long timeout= fTestIntrospector.getTimeout(fMethod); if (timeout > 0) runWithTimeout(timeout); else runMethod(); } finally { fNotifier.fireTestFinished(fDescription); } } private void runWithTimeout(long timeout) { ExecutorService service= Executors.newSingleThreadExecutor(); Callable<Object> callable= new Callable<Object>() { public Object call() throws Exception { runMethod(); return null; } }; Future<Object> result= service.submit(callable); service.shutdown(); try { boolean terminated= service.awaitTermination(timeout, TimeUnit.MILLISECONDS); if (!terminated) service.shutdownNow(); result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation } catch (TimeoutException e) { addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout))); } catch (Exception e) { addFailure(e); } } private void runMethod() { runProtected(); } @Override protected void runUnprotected() { try { executeMethodBody(); if (expectsException()) addFailure(new AssertionError("Expected exception: " + expectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); if (!expectsException()) addFailure(actual); else if (isUnexpected(actual)) { String message= "Unexpected exception, expected<" + expectedException().getName() + "> but was<" + actual.getClass().getName() + ">"; addFailure(new Exception(message, actual)); } } catch (Throwable e) { addFailure(e); } } protected void executeMethodBody() throws IllegalAccessException, InvocationTargetException { fMethod.invoke(fTest); } @Override protected void addFailure(Throwable e) { fNotifier.fireTestFailure(new Failure(fDescription, e)); } private boolean expectsException() { return expectedException() != null; } private Class<? extends Throwable> expectedException() { return fTestIntrospector.expectedException(fMethod); } private boolean isUnexpected(Throwable exception) { return ! expectedException().isAssignableFrom(exception.getClass()); } } --- NEW FILE: OldTestClassRunner.java --- package org.junit.internal.runners; import junit.extensions.TestDecorator; import junit.framework.AssertionFailedError; import junit.framework.JUnit4TestAdapter; import junit.framework.JUnit4TestCaseFacade; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestListener; import junit.framework.TestResult; import junit.framework.TestSuite; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.notification.RunNotifier; import org.junit.runner.notification.Failure; public class OldTestClassRunner extends Runner { private Test fTest; @SuppressWarnings("unchecked") public OldTestClassRunner(Class<?> klass) { this(new TestSuite(klass.asSubclass(TestCase.class))); } public OldTestClassRunner(Test test) { super(); fTest= test; } @Override public void run(RunNotifier notifier) { TestResult result= new TestResult(); result.addListener(getListener(notifier)); fTest.run(result); } private TestListener getListener(final RunNotifier notifier) { return new TestListener() { public void endTest(Test test) { // TODO: uncovered notifier.fireTestFinished(asDescription(test)); } public void startTest(Test test) { notifier.fireTestStarted(asDescription(test)); } // Implement junit.framework.TestListener //TODO method not covered public void addError(Test test, Throwable t) { Failure failure= new Failure(asDescription(test), t); notifier.fireTestFailure(failure); } private Description asDescription(Test test) { if (test instanceof JUnit4TestCaseFacade) { JUnit4TestCaseFacade facade= (JUnit4TestCaseFacade) test; return facade.getDescription(); } return Description.createTestDescription(test.getClass(), getName(test)); } private String getName(Test test) { if (test instanceof TestCase) return ((TestCase) test).getName(); else return test.toString(); } //TODO method not covered public void addFailure(Test test, AssertionFailedError t) { addError(test, t); } }; } @Override public Description getDescription() { return makeDescription(fTest); } private Description makeDescription(Test test) { if (test instanceof TestCase) { TestCase tc= (TestCase) test; return Description.createTestDescription(tc.getClass(), tc.getName()); } else if (test instanceof TestSuite) { TestSuite ts= (TestSuite) test; String name= ts.getName() == null ? "" : ts.getName(); Description description= Description.createSuiteDescription(name); int n= ts.testCount(); for (int i= 0; i < n; i++) description.addChild(makeDescription(ts.testAt(i))); return description; } else if (test instanceof JUnit4TestAdapter) { JUnit4TestAdapter adapter= (JUnit4TestAdapter) test; return adapter.getDescription(); } else if (test instanceof TestDecorator) { TestDecorator decorator= (TestDecorator) test; return makeDescription(decorator.getTest()); } else { // This is the best we can do in this case return Description.createSuiteDescription(test.getClass()); } } } --- NEW FILE: package-info.java --- /** * Provides implementations of {@link org.junit.runner.Runner} * * @since 4.0 */ package org.junit.internal.runners; --- NEW FILE: InitializationError.java --- package org.junit.internal.runners; import java.util.Arrays; import java.util.List; public class InitializationError extends Exception { private static final long serialVersionUID= 1L; private final List<Throwable> fErrors; public InitializationError(List<Throwable> errors) { fErrors= errors; } public InitializationError(Throwable... errors) { this(Arrays.asList(errors)); } public InitializationError(String string) { this(new Exception(string)); } public List<Throwable> getCauses() { return fErrors; } } --- NEW FILE: EmptyDescription.java --- package org.junit.internal.runners; import org.junit.runner.Description; public class EmptyDescription extends Description { public EmptyDescription() { super("No Tests"); } @Override public boolean equals(Object obj) { return getClass().equals(obj.getClass()); } @Override public int hashCode() { return 0; } } --- NEW FILE: BeforeAndAfterRunner.java --- package org.junit.internal.runners; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; public abstract class BeforeAndAfterRunner { private static class FailedBefore extends Exception { private static final long serialVersionUID= 1L; } private final Class<? extends Annotation> fBeforeAnnotation; private final Class<? extends Annotation> fAfterAnnotation; private TestIntrospector fTestIntrospector; private Object fTest; public BeforeAndAfterRunner(Class<?> testClass, Class<? extends Annotation> beforeAnnotation, Class<? extends Annotation> afterAnnotation, Object test) { fBeforeAnnotation= beforeAnnotation; fAfterAnnotation= afterAnnotation; fTestIntrospector= new TestIntrospector(testClass); fTest= test; } public void runProtected() { try { runBefores(); runUnprotected(); } catch (FailedBefore e) { } finally { runAfters(); } } protected abstract void runUnprotected(); protected abstract void addFailure(Throwable targetException); // Stop after first failed @Before private void runBefores() throws FailedBefore { try { List<Method> befores= fTestIntrospector.getTestMethods(fBeforeAnnotation); for (Method before : befores) invokeMethod(before); } catch (InvocationTargetException e) { addFailure(e.getTargetException()); throw new FailedBefore(); } catch (Throwable e) { addFailure(e); throw new FailedBefore(); } } // Try to run all @Afters regardless private void runAfters() { List<Method> afters= fTestIntrospector.getTestMethods(fAfterAnnotation); for (Method after : afters) try { invokeMethod(after); } catch (InvocationTargetException e) { addFailure(e.getTargetException()); } catch (Throwable e) { addFailure(e); // Untested, but seems impossible } } private void invokeMethod(Method method) throws Exception { method.invoke(fTest); } } |
From: David S. <ds...@us...> - 2006-11-21 18:53:55
|
Update of /cvsroot/junit/junit/src/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/src/junit/tests Added Files: AllTests.java WasRun.java package-info.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- NEW FILE: AllTests.java --- package junit.tests; import junit.framework.Test; import junit.framework.TestSuite; /** * TestSuite that runs all the JUnit tests * */ public class AllTests { public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { TestSuite suite= new TestSuite("Framework Tests"); suite.addTest(junit.tests.framework.AllTests.suite()); suite.addTest(junit.tests.runner.AllTests.suite()); suite.addTest(junit.tests.extensions.AllTests.suite()); return suite; } } --- NEW FILE: WasRun.java --- package junit.tests; import junit.framework.TestCase; /** * A helper test case for testing whether the testing method * is run. */ public class WasRun extends TestCase { public boolean fWasRun= false; @Override protected void runTest() { fWasRun= true; } } --- NEW FILE: package-info.java --- /** * Tests the JUnit v3.x framework. */ package junit.tests; |
From: David S. <ds...@us...> - 2006-11-21 18:53:54
|
Update of /cvsroot/junit/junit/org/junit/samples/money In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/org/junit/samples/money Removed Files: package-info.java MoneyTest.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- package-info.java DELETED --- --- MoneyTest.java DELETED --- |
From: David S. <ds...@us...> - 2006-11-21 18:53:54
|
Update of /cvsroot/junit/junit/src/org/junit/internal In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/src/org/junit/internal Added Files: ArrayComparisonFailure.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- NEW FILE: ArrayComparisonFailure.java --- package org.junit.internal; import java.util.ArrayList; import java.util.List; import org.junit.Assert; /** * Thrown when two array elements differ * @see Assert#assertEquals(String, Object[], Object[]) */ public class ArrayComparisonFailure extends AssertionError { private static final long serialVersionUID= 1L; private List<Integer> fIndices= new ArrayList<Integer>(); private final String fMessage; private final AssertionError fCause; /** * Construct a new <code>ArrayComparisonFailure</code> with an error text and the array's * dimension that was not equal * @param cause the exception that caused the array's content to fail the assertion test * @param index the array position of the objects that are not equal. * @see Assert#assertEquals(String, Object[], Object[]) */ public ArrayComparisonFailure(String message, AssertionError cause, int index) { fMessage= message; fCause= cause; addDimension(index); } public void addDimension(int index) { fIndices.add(0, index); } @Override public String getMessage() { StringBuilder builder= new StringBuilder(); if (fMessage != null) builder.append(fMessage); builder.append("arrays first differed at element "); for (int each : fIndices) { builder.append("["); builder.append(each); builder.append("]"); } builder.append("; "); builder.append(fCause.getMessage()); return builder.toString(); } /** * {@inheritDoc} */ @Override public String toString() { return getMessage(); } } |
From: David S. <ds...@us...> - 2006-11-21 18:53:54
|
Update of /cvsroot/junit/junit/org/junit/runner/notification In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/org/junit/runner/notification Removed Files: Failure.java RunNotifier.java RunListener.java StoppedByUserException.java package-info.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- Failure.java DELETED --- --- RunNotifier.java DELETED --- --- RunListener.java DELETED --- --- StoppedByUserException.java DELETED --- --- package-info.java DELETED --- |
Update of /cvsroot/junit/junit/src/junit/runner In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/src/junit/runner Added Files: Version.java smalllogo.gif logo.gif TestRunListener.java Version.java.template package-info.java BaseTestRunner.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- NEW FILE: Version.java --- package junit.runner; /** * This class defines the current version of JUnit */ public class Version { private Version() { // don't instantiate } public static String id() { return "4.2"; } public static void main(String[] args) { System.out.println(id()); } } --- NEW FILE: smalllogo.gif --- GIF89a L¨@`Hq"C%fH¡Â+"ðØP¤Á9¦ìøqäGUIS$É_ªiQgD(]äÉ!É+â\Z3 --- NEW FILE: logo.gif --- GIF89a& ¿õºÑjÒ)w½z'Χ3¥R-JnÛ¥b¼Eº.W½{Ùö;Õ£UÁ~ÿD;¶q@ --- NEW FILE: TestRunListener.java --- package junit.runner; /** * A listener interface for observing the * execution of a test run. Unlike TestListener, * this interface using only primitive objects, * making it suitable for remote test execution. */ public interface TestRunListener { /* test status constants*/ public static final int STATUS_ERROR= 1; public static final int STATUS_FAILURE= 2; public void testRunStarted(String testSuiteName, int testCount); public void testRunEnded(long elapsedTime); public void testRunStopped(long elapsedTime); public void testStarted(String testName); public void testEnded(String testName); public void testFailed(int status, String testName, String trace); } --- NEW FILE: Version.java.template --- 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@"; } public static void main(String[] args) { System.out.println(id()); } } --- NEW FILE: package-info.java --- /** * Provides JUnit v3.x test runners. */ package junit.runner; --- NEW FILE: BaseTestRunner.java --- package junit.runner; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.text.NumberFormat; import java.util.Properties; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestListener; import junit.framework.TestSuite; /** * Base class for all test runners. * This class was born live on stage in Sardinia during XP2000. */ public abstract class BaseTestRunner implements TestListener { public static final String SUITE_METHODNAME= "suite"; private static Properties fPreferences; static int fgMaxMessageLength= 500; static boolean fgFilterStack= true; boolean fLoading= true; /* * Implementation of TestListener */ public synchronized void startTest(Test test) { testStarted(test.toString()); } protected static void setPreferences(Properties preferences) { fPreferences= preferences; } protected static Properties getPreferences() { if (fPreferences == null) { fPreferences= new Properties(); fPreferences.put("loading", "true"); fPreferences.put("filterstack", "true"); readPreferences(); } return fPreferences; } public static void savePreferences() throws IOException { FileOutputStream fos= new FileOutputStream(getPreferencesFile()); try { getPreferences().store(fos, ""); } finally { fos.close(); } } public static void setPreference(String key, String value) { getPreferences().put(key, value); } public synchronized void endTest(Test test) { testEnded(test.toString()); } public synchronized void addError(final Test test, final Throwable t) { testFailed(TestRunListener.STATUS_ERROR, test, t); } public synchronized void addFailure(final Test test, final AssertionFailedError t) { testFailed(TestRunListener.STATUS_FAILURE, test, t); } // TestRunListener implementation public abstract void testStarted(String testName); public abstract void testEnded(String testName); public abstract void testFailed(int status, Test test, Throwable t); /** * Returns the Test corresponding to the given suite. This is * a template method, subclasses override runFailed(), clearStatus(). */ public Test getTest(String suiteClassName) { if (suiteClassName.length() <= 0) { clearStatus(); return null; } Class<? extends TestCase> testClass= null; try { testClass= loadSuiteClass(suiteClassName); } catch (ClassNotFoundException e) { String clazz= e.getMessage(); if (clazz == null) clazz= suiteClassName; runFailed("Class not found \""+clazz+"\""); return null; } catch(Exception e) { runFailed("Error: "+e.toString()); return null; } Method suiteMethod= null; try { suiteMethod= testClass.getMethod(SUITE_METHODNAME, new Class[0]); } catch(Exception e) { // try to extract a test suite automatically clearStatus(); return new TestSuite(testClass); } if (! Modifier.isStatic(suiteMethod.getModifiers())) { runFailed("Suite() method must be static"); return null; } Test test= null; try { test= (Test)suiteMethod.invoke(null, (Object[])new Class[0]); // static method if (test == null) return test; } 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; } /** * Returns the formatted string of the elapsed time. */ public String elapsedTimeAsString(long runTime) { return NumberFormat.getInstance().format((double)runTime/1000); } /** * Processes the command line arguments and * returns the name of the suite class to run or null */ protected String processArguments(String[] args) { String suiteName= null; for (int i= 0; i < args.length; i++) { if (args[i].equals("-noloading")) { setLoading(false); } else if (args[i].equals("-nofilterstack")) { fgFilterStack= false; } else if (args[i].equals("-c")) { if (args.length > i+1) suiteName= extractClassName(args[i+1]); else System.out.println("Missing Test class name"); i++; } else { suiteName= args[i]; } } return suiteName; } /** * Sets the loading behaviour of the test runner */ public void setLoading(boolean enable) { fLoading= enable; } /** * Extract the class name from a String in VA/Java style */ public String extractClassName(String className) { if(className.startsWith("Default package for")) return className.substring(className.lastIndexOf(".")+1); return className; } /** * Truncates a String to the maximum length. */ public static String truncate(String s) { if (fgMaxMessageLength != -1 && s.length() > fgMaxMessageLength) s= s.substring(0, fgMaxMessageLength)+"..."; return s; } /** * Override to define how to handle a failed loading of * a test suite. */ protected abstract void runFailed(String message); /** * Returns the loaded Class for a suite name. */ protected Class<? extends TestCase> loadSuiteClass(String suiteClassName) throws ClassNotFoundException { return Class.forName(suiteClassName).asSubclass(TestCase.class); } /** * Clears the status message. */ protected void clearStatus() { // Belongs in the GUI TestRunner class } protected boolean useReloadingTestSuiteLoader() { return getPreference("loading").equals("true") && fLoading; } private static File getPreferencesFile() { String home= System.getProperty("user.home"); return new File(home, "junit.properties"); } private static void readPreferences() { InputStream is= null; try { is= new FileInputStream(getPreferencesFile()); setPreferences(new Properties(getPreferences())); getPreferences().load(is); } catch (IOException e) { try { if (is != null) is.close(); } catch (IOException e1) { } } } public static String getPreference(String key) { return getPreferences().getProperty(key); } public static int getPreference(String key, int dflt) { String value= getPreference(key); int intValue= dflt; if (value == null) return intValue; try { intValue= Integer.parseInt(value); } catch (NumberFormatException ne) { } return intValue; } /** * Returns a filtered stack trace */ public static String getFilteredTrace(Throwable t) { StringWriter stringWriter= new StringWriter(); PrintWriter writer= new PrintWriter(stringWriter); t.printStackTrace(writer); StringBuffer buffer= stringWriter.getBuffer(); String trace= buffer.toString(); return BaseTestRunner.getFilteredTrace(trace); } /** * Filters stack frames from internal JUnit classes */ public static String getFilteredTrace(String stack) { if (showStackRaw()) return stack; StringWriter sw= new StringWriter(); PrintWriter pw= new PrintWriter(sw); StringReader sr= new StringReader(stack); BufferedReader br= new BufferedReader(sr); String line; try { while ((line= br.readLine()) != null) { if (!filterLine(line)) pw.println(line); } } catch (Exception IOException) { return stack; // return the stack unfiltered } return sw.toString(); } protected static boolean showStackRaw() { return !getPreference("filterstack").equals("true") || fgFilterStack == false; } static boolean filterLine(String line) { String[] patterns= new String[] { "junit.framework.TestCase", "junit.framework.TestResult", "junit.framework.TestSuite", "junit.framework.Assert.", // don't filter AssertionFailure "junit.swingui.TestRunner", "junit.awtui.TestRunner", "junit.textui.TestRunner", "java.lang.reflect.Method.invoke(" }; for (int i= 0; i < patterns.length; i++) { if (line.indexOf(patterns[i]) > 0) return true; } return false; } static { fgMaxMessageLength= getPreference("maxmessage", fgMaxMessageLength); } } |
From: David S. <ds...@us...> - 2006-11-21 18:53:54
|
Update of /cvsroot/junit/junit/src/junit/tests/runner In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/src/junit/tests/runner Added Files: package-info.java TextRunnerTest.java AllTests.java StackFilterTest.java BaseTestRunnerTest.java TextRunnerSingleMethodTest.java TextFeedbackTest.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- NEW FILE: package-info.java --- /** * Tests for the JUnit v3.x runner functionality. */ package junit.tests.runner; --- NEW FILE: TextRunnerTest.java --- package junit.tests.runner; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import junit.framework.TestCase; import junit.framework.TestResult; import junit.framework.TestSuite; public class TextRunnerTest extends TestCase { public void testFailure() throws Exception { execTest("junit.tests.framework.Failure", false); } public void testSuccess() throws Exception { execTest("junit.tests.framework.Success", true); } public void testError() throws Exception { execTest("junit.tests.BogusDude", false); } void execTest(String testClass, boolean success) throws Exception { String java= System.getProperty("java.home")+File.separator+"bin"+File.separator+"java"; String cp= System.getProperty("java.class.path"); //use -classpath for JDK 1.1.7 compatibility String [] cmd= { java, "-classpath", cp, "junit.textui.TestRunner", testClass}; Process p= Runtime.getRuntime().exec(cmd); InputStream i= p.getInputStream(); while((i.read()) != -1) ; //System.out.write(b); assertTrue((p.waitFor() == 0) == success); if (success) assertTrue(p.exitValue() == 0); else assertFalse(p.exitValue() == 0); } public void testRunReturnsResult() { PrintStream oldOut= System.out; System.setOut(new PrintStream ( new OutputStream() { @Override public void write(int arg0) throws IOException { } } )); try { TestResult result= junit.textui.TestRunner.run(new TestSuite()); assertTrue(result.wasSuccessful()); } finally { System.setOut(oldOut); } } } --- NEW FILE: AllTests.java --- package junit.tests.runner; import junit.framework.Test; import junit.framework.TestSuite; /** * TestSuite that runs all the sample tests * */ public class AllTests { public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { // Collect tests manually because we have to test class collection code TestSuite suite= new TestSuite("Framework Tests"); suite.addTestSuite(StackFilterTest.class); suite.addTestSuite(BaseTestRunnerTest.class); suite.addTestSuite(TextFeedbackTest.class); suite.addTestSuite(TextRunnerSingleMethodTest.class); suite.addTestSuite(TextRunnerTest.class); return suite; } static boolean isJDK11() { String version= System.getProperty("java.version"); return version.startsWith("1.1"); } } --- NEW FILE: StackFilterTest.java --- package junit.tests.runner; import java.io.PrintWriter; import java.io.StringWriter; import junit.framework.TestCase; import junit.runner.BaseTestRunner; public class StackFilterTest extends TestCase { String fFiltered; String fUnfiltered; @Override protected void setUp() { StringWriter swin= new StringWriter(); PrintWriter pwin= new PrintWriter(swin); pwin.println("junit.framework.AssertionFailedError"); pwin.println(" at junit.framework.Assert.fail(Assert.java:144)"); pwin.println(" at junit.framework.Assert.assert(Assert.java:19)"); pwin.println(" at junit.framework.Assert.assert(Assert.java:26)"); pwin.println(" at MyTest.f(MyTest.java:13)"); pwin.println(" at MyTest.testStackTrace(MyTest.java:8)"); pwin.println(" at java.lang.reflect.Method.invoke(Native Method)"); pwin.println(" at junit.framework.TestCase.runTest(TestCase.java:156)"); pwin.println(" at junit.framework.TestCase.runBare(TestCase.java:130)"); pwin.println(" at junit.framework.TestResult$1.protect(TestResult.java:100)"); pwin.println(" at junit.framework.TestResult.runProtected(TestResult.java:118)"); pwin.println(" at junit.framework.TestResult.run(TestResult.java:103)"); pwin.println(" at junit.framework.TestCase.run(TestCase.java:121)"); pwin.println(" at junit.framework.TestSuite.runTest(TestSuite.java:157)"); pwin.println(" at junit.framework.TestSuite.run(TestSuite.java, Compiled Code)"); pwin.println(" at junit.swingui.TestRunner$17.run(TestRunner.java:669)"); fUnfiltered= swin.toString(); StringWriter swout= new StringWriter(); PrintWriter pwout= new PrintWriter(swout); pwout.println("junit.framework.AssertionFailedError"); pwout.println(" at MyTest.f(MyTest.java:13)"); pwout.println(" at MyTest.testStackTrace(MyTest.java:8)"); fFiltered= swout.toString(); } public void testFilter() { assertEquals(fFiltered, BaseTestRunner.getFilteredTrace(fUnfiltered)); } } --- NEW FILE: BaseTestRunnerTest.java --- package junit.tests.runner; import junit.framework.Test; import junit.framework.TestCase; import junit.runner.BaseTestRunner; public class BaseTestRunnerTest extends TestCase { public static class MockRunner extends BaseTestRunner { @Override protected void runFailed(String message) { } @Override public void testEnded(String testName) { } @Override public void testFailed(int status, Test test, Throwable t) { } @Override public void testStarted(String testName) { } } public static class NonStatic { public Test suite() { return null; } } public void testInvokeNonStaticSuite() { BaseTestRunner runner= new MockRunner(); runner.getTest("junit.tests.runner.BaseTestRunnerTest$NonStatic"); // Used to throw NullPointerException } } --- NEW FILE: TextRunnerSingleMethodTest.java --- package junit.tests.runner; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import junit.framework.TestCase; import junit.textui.ResultPrinter; import junit.textui.TestRunner; /** * Test invoking a single test method of a TestCase. */ public class TextRunnerSingleMethodTest extends TestCase { static boolean fgWasInvoked; public static class InvocationTest extends TestCase { public void testWasInvoked() { TextRunnerSingleMethodTest.fgWasInvoked= true; } public void testNotInvoked() { fail("Shouldn't get here."); } } public void testSingle() throws Exception { TestRunner t= new TestRunner(); t.setPrinter(new ResultPrinter(new PrintStream(new ByteArrayOutputStream()))); String[] args= { "-m", "junit.tests.runner.TextRunnerSingleMethodTest$InvocationTest.testWasInvoked" }; fgWasInvoked= false; t.start(args); assertTrue(fgWasInvoked); } } --- NEW FILE: TextFeedbackTest.java --- package junit.tests.runner; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.PrintStream; import junit.framework.AssertionFailedError; import junit.framework.TestCase; import junit.framework.TestResult; import junit.framework.TestSuite; import junit.textui.ResultPrinter; import junit.textui.TestRunner; public class TextFeedbackTest extends TestCase { OutputStream output; TestRunner runner; static class TestResultPrinter extends ResultPrinter { TestResultPrinter(PrintStream writer) { super(writer); } /* Spoof printing time so the tests are deterministic */ @Override protected String elapsedTimeAsString(long runTime) { return "0"; } } public static void main(String[] args) { TestRunner.run(TextFeedbackTest.class); } @Override public void setUp() { output= new ByteArrayOutputStream(); runner= new TestRunner(new TestResultPrinter(new PrintStream(output))); } public void testEmptySuite() { String expected= expected(new String[]{"", "Time: 0", "", "OK (0 tests)", ""}); runner.doRun(new TestSuite()); assertEquals(expected, output.toString()); } public void testOneTest() { String expected= expected(new String[]{".", "Time: 0", "", "OK (1 test)", ""}); TestSuite suite = new TestSuite(); suite.addTest(new TestCase() { @Override public void runTest() {}}); runner.doRun(suite); assertEquals(expected, output.toString()); } public void testTwoTests() { String expected= expected(new String[]{"..", "Time: 0", "", "OK (2 tests)", ""}); TestSuite suite = new TestSuite(); suite.addTest(new TestCase() { @Override public void runTest() {}}); suite.addTest(new TestCase() { @Override public void runTest() {}}); runner.doRun(suite); assertEquals(expected, output.toString()); } public void testFailure() { String expected= expected(new String[]{".F", "Time: 0", "Failures here", "", "FAILURES!!!", "Tests run: 1, Failures: 1, Errors: 0", ""}); ResultPrinter printer= new TestResultPrinter(new PrintStream(output)) { @Override public void printFailures(TestResult result) { getWriter().println("Failures here"); } }; runner.setPrinter(printer); TestSuite suite = new TestSuite(); suite.addTest(new TestCase() { @Override public void runTest() {throw new AssertionFailedError();}}); runner.doRun(suite); assertEquals(expected, output.toString()); } public void testError() { String expected= expected(new String[]{".E", "Time: 0", "Errors here", "", "FAILURES!!!", "Tests run: 1, Failures: 0, Errors: 1", ""}); ResultPrinter printer= new TestResultPrinter(new PrintStream(output)) { @Override public void printErrors(TestResult result) { getWriter().println("Errors here"); } }; runner.setPrinter(printer); TestSuite suite = new TestSuite(); suite.addTest(new TestCase() { @Override public void runTest() throws Exception {throw new Exception();}}); runner.doRun(suite); assertEquals(expected, output.toString()); } private String expected(String[] lines) { OutputStream expected= new ByteArrayOutputStream(); PrintStream expectedWriter= new PrintStream(expected); for (int i= 0; i < lines.length; i++) expectedWriter.println(lines[i]); return expected.toString(); } } |
Update of /cvsroot/junit/junit/org/junit/internal/requests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/org/junit/internal/requests Removed Files: ErrorReportingRequest.java SortingRequest.java package-info.java FilterRequest.java ClassRequest.java ClassesRequest.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- ErrorReportingRequest.java DELETED --- --- SortingRequest.java DELETED --- --- package-info.java DELETED --- --- FilterRequest.java DELETED --- --- ClassRequest.java DELETED --- --- ClassesRequest.java DELETED --- |
From: David S. <ds...@us...> - 2006-11-21 18:53:54
|
Update of /cvsroot/junit/junit/junit/textui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19867/junit/textui Removed Files: TestRunner.java package-info.java ResultPrinter.java Log Message: Created a separate src folder for sources, and adjusted Eclipse classpath and build file accordingly --- TestRunner.java DELETED --- --- package-info.java DELETED --- --- ResultPrinter.java DELETED --- |