Author: sebb
Date: Mon Sep 21 20:26:05 2009
New Revision: 817402
URL: http://svn.apache.org/viewvc?rev=817402&view=rev
Log:
Enhance JUnit4 sample tests
Modified:
jakarta/jmeter/trunk/src/junit/test/DummyAnnotatedTest.java
Modified: jakarta/jmeter/trunk/src/junit/test/DummyAnnotatedTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/junit/test/DummyAnnotatedTest.java?rev=817402&r1=817401&r2=817402&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/junit/test/DummyAnnotatedTest.java (original)
+++ jakarta/jmeter/trunk/src/junit/test/DummyAnnotatedTest.java Mon Sep 21
20:26:05 2009
@@ -18,10 +18,15 @@
package test;
+import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+/**
+ * Sample test cases for demonstrating JUnit4 sampler.
+ *
+ */
public class DummyAnnotatedTest
{
public String name;
@@ -30,26 +35,35 @@
public DummyAnnotatedTest() {
name="NOT SET";
}
+
public DummyAnnotatedTest(String name) {
this.name = name;
}
+ // Generates expected Exception
@Test(expected=RuntimeException.class)
- public void fail() {
+ public void expectedExceptionPass() {
throw new RuntimeException();
}
+ // Fails to generate expected Exception
+ @Test(expected=RuntimeException.class)
+ public void expectedExceptionFail() {
+ }
+
@Before
public void verifyTwo() {
+ System.out.println("DummyAnnotatedTest#verifyTwo()");
two = 2;
}
@After
public void printDone() {
- System.out.println("done with an annotated test.");
+ System.out.println("DummyAnnotatedTest#printDone()");
}
@Test
+ // Succeeds only if Before method - verifyTwo() - is run.
public void add() {
int four = two+2;
if(4!=four) {
@@ -61,9 +75,29 @@
//should always fail
@Test(timeout=1000)
- public void timeOut() {
+ public void timeOutFail() {
try{
Thread.sleep(2000);
}catch (InterruptedException e) { }
}
+
+ //should not fail
+ @Test(timeout=1000)
+ public void timeOutPass() {
+ try{
+ Thread.sleep(500);
+ }catch (InterruptedException e) { }
+ }
+
+ @Test
+ public void alwaysFail() {
+ fail("This always fails");
+ }
+
+ @Test
+ // Generate a test error
+ public void divideByZero() {
+ @SuppressWarnings("unused")
+ int i = 27 / 0; // will generate Divide by zero error
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]