[testng] 253/355: Rework failed test
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:12 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.
commit f7ec38df6e0c010a623d707c05e41763768b4005
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date: Sun May 3 15:04:10 2015 +0200
Rework failed test
---
pom-test.xml | 6 +++
pom.xml | 6 +++
.../AnnotationTransformerSampleTest.java | 19 --------
.../AnnotationTransformerTest.java | 51 +++++++++++++++++-----
.../test/annotationtransformer/MyTransformer.java | 34 ++++++++-------
5 files changed, 70 insertions(+), 46 deletions(-)
diff --git a/pom-test.xml b/pom-test.xml
index 212bada..3a8f643 100644
--- a/pom-test.xml
+++ b/pom-test.xml
@@ -79,6 +79,12 @@
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>2.0.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/pom.xml b/pom.xml
index 829625b..0f54a85 100644
--- a/pom.xml
+++ b/pom.xml
@@ -132,6 +132,12 @@
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>2.0.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<properties>
diff --git a/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java b/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java
index 6ae3efd..e930be7 100644
--- a/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java
+++ b/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java
@@ -14,25 +14,21 @@ public class AnnotationTransformerSampleTest {
@Test(invocationCount = 2)
public void two() {
m_two++;
- ppp("Should be invoked 2 times");
}
@Test(invocationCount = 5)
public void four() {
m_four++;
- ppp("Should be invoked 4 times");
}
@Test(invocationCount = 5)
public void three() {
m_three++;
- ppp("Should be invoked 3 times");
}
@Test
public void five() {
m_five++;
- ppp("Should be invoked 5 times");
}
@Test(dependsOnMethods = {"two", "three", "four", "five"})
@@ -41,20 +37,5 @@ public class AnnotationTransformerSampleTest {
Assert.assertEquals(m_three, 3);
Assert.assertEquals(m_four, 4);
Assert.assertEquals(m_five, 5);
-
- }
-
- public static void main(String[] argv) {
- TestNG tng = new TestNG();
- tng.setAnnotationTransformer(new MyTransformer());
- tng.setTestClasses(new Class[] { AnnotationTransformerSampleTest.class});
-
- tng.run();
- }
-
- private void ppp(String string) {
- if (false) {
- System.out.println("[AnnotationTransformerSampleTest] " + string);
- }
}
}
diff --git a/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java b/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java
index 16be028..71390b5 100644
--- a/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java
+++ b/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java
@@ -1,5 +1,6 @@
package test.annotationtransformer;
+import org.assertj.core.api.iterable.Extractor;
import org.testng.Assert;
import org.testng.IAnnotationTransformer;
import org.testng.ITestResult;
@@ -16,24 +17,40 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class AnnotationTransformerTest extends SimpleBaseTest {
+ private static final Extractor NAME_EXTRACTOR = new Extractor<ITestResult, String>() {
+ @Override
+ public String extract(ITestResult input) {
+ return input.getName();
+ }
+ };
+
/**
* Make sure that without a transformer in place, a class-level
* annotation invocationCount is correctly used.
*/
@Test
public void verifyAnnotationWithoutTransformer() {
- TestNG tng = new TestNG();
- tng.setVerbose(0);
- tng.setTestClasses(new Class[] { AnnotationTransformerClassInvocationSampleTest.class});
+ TestNG tng = create(AnnotationTransformerSampleTest.class);
+ tng.setPreserveOrder(true);
+
TestListenerAdapter tla = new TestListenerAdapter();
tng.addListener(tla);
tng.run();
- List passed = tla.getPassedTests();
- Assert.assertEquals(passed.size(), 6);
+ assertThat(tla.getPassedTests()).extracting(NAME_EXTRACTOR)
+ .containsExactly(
+ "five",
+ "four", "four", "four", "four", "four",
+ "three", "three", "three", "three", "three",
+ "two", "two"
+ );
+ assertThat(tla.getFailedTests()).extracting(NAME_EXTRACTOR)
+ .containsExactly("verify");
}
/**
@@ -41,17 +58,29 @@ public class AnnotationTransformerTest extends SimpleBaseTest {
*/
@Test
public void verifyAnnotationTransformerMethod() {
- TestNG tng = new TestNG();
- tng.setVerbose(0);
- tng.setAnnotationTransformer(new MyTransformer());
- tng.setTestClasses(new Class[] { AnnotationTransformerSampleTest.class});
+ TestNG tng = create(AnnotationTransformerSampleTest.class);
+ tng.setPreserveOrder(true);
+ tng.setVerbose(10);
+
+ MyTransformer transformer = new MyTransformer();
+ tng.setAnnotationTransformer(transformer);
+
TestListenerAdapter tla = new TestListenerAdapter();
tng.addListener(tla);
tng.run();
- List passed = tla.getPassedTests();
- Assert.assertEquals(passed.size(), 15);
+ assertThat(transformer.getMethodNames()).contains("two", "three", "four", "five", "verify");
+
+ assertThat(tla.getPassedTests()).extracting(NAME_EXTRACTOR)
+ .containsExactly(
+ "five", "five", "five", "five", "five",
+ "four", "four", "four", "four",
+ "three", "three", "three",
+ "two", "two",
+ "verify"
+ );
+ assertThat(tla.getFailedTests()).isEmpty();
}
/**
diff --git a/src/test/java/test/annotationtransformer/MyTransformer.java b/src/test/java/test/annotationtransformer/MyTransformer.java
index 577003d..b3eeeb4 100644
--- a/src/test/java/test/annotationtransformer/MyTransformer.java
+++ b/src/test/java/test/annotationtransformer/MyTransformer.java
@@ -5,32 +5,34 @@ import org.testng.annotations.ITestAnnotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
public class MyTransformer implements IAnnotationTransformer {
+ private final List<String> methodNames = new ArrayList<>();
+
@Override
public void transform(ITestAnnotation annotation, Class testClass,
- Constructor testConstructor, Method testMethod)
- {
+ Constructor testConstructor, Method testMethod) {
annotation.setTimeOut(10000);
if (testMethod != null) {
- String name = testMethod.getName();
- if ("three".equals(name)) {
- annotation.setInvocationCount(3);
- }
- else if ("four".equals(name)) {
- annotation.setInvocationCount(4);
- }
- else if ("five".equals(name)) {
- annotation.setInvocationCount(5);
+ switch (testMethod.getName()) {
+ case "three":
+ annotation.setInvocationCount(3);
+ break;
+ case "four":
+ annotation.setInvocationCount(4);
+ break;
+ case "five":
+ annotation.setInvocationCount(5);
+ break;
}
+ methodNames.add(testMethod.getName());
}
}
- private void ppp(String string) {
- System.out.println("[MyTransformer] " + string);
+ public List<String> getMethodNames() {
+ return methodNames;
}
-
-
-
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list