Author: krosenvold
Date: Wed Jan 12 20:12:50 2011
New Revision: 1058301
URL: http://svn.apache.org/viewvc?rev=1058301&view=rev
Log:
[SUREFIRE-498] Properly implement fixture support in pojo provider
Patch by Christian Gruber, applied with modifications
Added:
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/pojo-test.apt
(with props)
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/index.apt
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/usage.apt
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
Added:
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/pojo-test.apt
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/pojo-test.apt?rev=1058301&view=auto
==============================================================================
---
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/pojo-test.apt
(added)
+++
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/pojo-test.apt
Wed Jan 12 20:12:50 2011
@@ -0,0 +1,30 @@
+ ------
+ Using POJO tests
+ ------
+ Christian Gruber
+ ------
+ May 2008
+ ------
+
+Defining a POJO Test
+
+ POJO tests look very much like JUnit or TestNG tests, though they do not
+ require dependencies on these artifacts. A test class should be named
+ <<<**/*Test>>> and should contain <<<test*>>> methods which will each be
+ executed by surefire.
+
+ Validating assertions can be done using the JDK 1.4 <<<assert>>> keyword.
+ Simultaneous test execution is not possible with POJO tests.
+
+ Fixture can be setup before and after each <<<test*>>> method by implementing
+ a set-up and a tear-down method. These methods must match these signatures
+ to be recognized and executed before and after each test method.
+
++---+
+public void setUp();
+public void tearDown();
++---+
+
+ These fixture methods can also throw any exception and will still be valid.
+
+
\ No newline at end of file
Propchange:
maven/surefire/trunk/maven-surefire-plugin/src/site/apt/examples/pojo-test.apt
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/maven-surefire-plugin/src/site/apt/index.apt
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/site/apt/index.apt?rev=1058301&r1=1058300&r2=1058301&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/site/apt/index.apt (original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/site/apt/index.apt Wed Jan
12 20:12:50 2011
@@ -79,6 +79,8 @@ Maven Surefire Plugin
* {{{./examples/junit.html}Using JUnit}}
+ * {{{./examples/pojo-test.html}Using POJO Tests}}
+
* {{{./examples/skipping-test.html}Skipping Tests}}
* {{{./examples/inclusion-exclusion.html}Inclusions and Exclusions of Tests}}
@@ -93,4 +95,5 @@ Maven Surefire Plugin
* {{{./examples/configuring-classpath.html}Configuring the Classpath}}
+
* {{{./examples/providers.html}Selecting providers}}
Modified: maven/surefire/trunk/maven-surefire-plugin/src/site/apt/usage.apt
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/site/apt/usage.apt?rev=1058301&r1=1058300&r2=1058301&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/site/apt/usage.apt (original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/site/apt/usage.apt Wed Jan
12 20:12:50 2011
@@ -61,6 +61,7 @@ mvn test
public in the class, but the API dependency is not required. To perform
assertions, the JDK 1.4 <<<assert>>> keyword can be used, or you can use
<<<org.apache.maven.surefire.assertion.Assert>>>.
+ See {{{examples/pojo-test.html} using POJO tests}} for more information.
All of the providers support the Surefire Plugin parameter configurations.
However, there are additional options available if you are running TestNG
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java?rev=1058301&r1=1058300&r2=1058301&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
Wed Jan 12 20:12:50 2011
@@ -43,6 +43,10 @@ public class PojoTestSet
private Object testObject;
protected List testMethods;
+
+ protected Method setUpMethod;
+
+ protected Method tearDownMethod;
private Class testClass;
@@ -129,7 +133,7 @@ public class PojoTestSet
{
setUpFixture();
}
- catch ( Exception e )
+ catch ( Throwable e )
{
report = new SimpleReportEntry( testObject.getClass().getName(),
getTestName( userFriendlyMethodName ),
new PojoStackTraceWriter(
testObject.getClass().getName(), method.getName(),
@@ -216,12 +220,14 @@ public class PojoTestSet
return getTestClass().getName() + "." + testMethodName;
}
- public void setUpFixture()
+ public void setUpFixture() throws Throwable
{
+ if (setUpMethod != null) setUpMethod.invoke( testObject, new Object[0]
);
}
- public void tearDownFixture()
+ public void tearDownFixture() throws Throwable
{
+ if (tearDownMethod != null) tearDownMethod.invoke( testObject, new
Object[0] );
}
private void discoverTestMethods()
@@ -252,6 +258,14 @@ public class PojoTestSet
}
}
}
+ else if (m.getName().equals("setUp") &&
m.getParameterTypes().length == 0)
+ {
+ setUpMethod = m;
+ }
+ else if (m.getName().equals("tearDown") &&
m.getParameterTypes().length == 0)
+ {
+ tearDownMethod = m;
+ }
}
}
}