From b310cd56f1039389aa360fbf51c6349e7a8e1f02 Mon Sep 17 00:00:00 2001 From: David Saff Date: Mon, 3 Jan 2011 13:33:50 -0500 Subject: [PATCH] Update JUnit version, improve ClassRule javadoc, update release notes --- build.xml | 2 +- doc/ReleaseNotes4.9.txt | 74 +++++++++++--------------- src/main/java/org/junit/ClassRule.java | 6 ++- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/build.xml b/build.xml index 7ecda3837706..3fdd9fee35c4 100644 --- a/build.xml +++ b/build.xml @@ -5,7 +5,7 @@ - + diff --git a/doc/ReleaseNotes4.9.txt b/doc/ReleaseNotes4.9.txt index 6fcfce024323..1949eeefb1f5 100644 --- a/doc/ReleaseNotes4.9.txt +++ b/doc/ReleaseNotes4.9.txt @@ -1,54 +1,42 @@ ## Summary of Changes in version 4.9 ## -### SuiteBuilder ### - -A new way of declaring suites to run. SuiteBuilder allows for flexible -specification of where to find the classes containing tests, and how -to filter the resulting runners. This suite class lists the -explicit test classes to consider running, and then filters it down -to only those tests or classes annotated with `@Category(Yes.class)`: - - @RunWith(SuiteBuilder.class) - public class OnlyYes { - @Classes - public Listed classes= new Listed(Yes1.class, Yes2.class, No1.class); - - @RunnerFilter - public CategoryFilter filter= CategoryFilter.include(Yes.class); - } - -We hope to soon include other implementations for the @Classes annotation, -including a classpath-searching test gatherer. - ### ClassRule ### -The ClassRule annotation extends the idea of method-level Rules, -adding static fields that can affect the operation of a whole class: +The `ClassRule` annotation extends the idea of method-level Rules, +adding static fields that can affect the operation of a whole class. - public class Counter extends ExternalResource { - public int count = 0; +For example, here is a test suite that connects to a server once before +all the test classes run, and disconnects after they are finished: - @Override - protected void before() throws Throwable { - count++; - } - } + @RunWith(Suite.class) + @SuiteClasses({A.class, B.class, C.class}) + public class UsesExternalResource { + public static Server myServer= new Server(); + + @Rule + public static ExternalResource resource= new ExternalResource() { + @Override + protected void before() throws Throwable { + myServer.connect(); + }; - public class ExampleTestWithClassRule { - @ClassRule - public static Counter counter= new Counter(); - - @Test - public void firstTest() { - assertEquals(1, counter.count); - } - - @Test - public void secondTest() { - assertEquals(1, counter.count); - } + @Override + protected void after() { + myServer.disconnect(); + }; + }; + + @Test public void test1() { ... } + @Test public void test2() { ... } + @Test public void test3() { ... } } +### TestRule ### + +In JUnit 4.9, fields that can be annotated with either `@Rule` or `@ClassRule` +should be of type `TestRule`. The old `MethodRule` type, which only made sense +for method-level rules, is now deprecated. + ### Bug fixes ### -- github#98: assumeTrue() does not work with expected exceptions \ No newline at end of file +- github#98: assumeTrue() does not work with expected exceptions diff --git a/src/main/java/org/junit/ClassRule.java b/src/main/java/org/junit/ClassRule.java index bccb03aa14d0..ba0ec500b1c3 100644 --- a/src/main/java/org/junit/ClassRule.java +++ b/src/main/java/org/junit/ClassRule.java @@ -31,7 +31,7 @@ * * @RunWith(Suite.class) * @SuiteClasses({A.class, B.class, C.class}) - * public static class UsesExternalResource { + * public class UsesExternalResource { * public static Server myServer= new Server(); * * @Rule @@ -46,6 +46,10 @@ * myServer.disconnect(); * }; * }; + * + * @Test public void test1() { ... } + * @Test public void test2() { ... } + * @Test public void test3() { ... } * } * *