Repository: maven-surefire Updated Branches: refs/heads/master 86d78ad1b -> f305e2ab2
SUREFIRE-1077 avoid NPE in stacktrace parsing if a test fails without a Throwable as cause Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/d78376b8 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/d78376b8 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/d78376b8 Branch: refs/heads/master Commit: d78376b82a18cec354cab32182e7c18af363f6f7 Parents: 86d78ad Author: Andreas Gudian <agud...@apache.org> Authored: Sat Sep 27 22:18:11 2014 +0200 Committer: Andreas Gudian <agud...@apache.org> Committed: Sat Sep 27 22:18:11 2014 +0200 ---------------------------------------------------------------------- .../surefire/its/CheckTestNgListenersIT.java | 37 +++++++++ .../src/test/resources/testng-listeners/pom.xml | 43 ++++++++++ .../java/listeners/MarkAsFailureListener.java | 83 ++++++++++++++++++++ .../src/test/java/listeners/SimpleTest.java | 35 +++++++++ .../surefire/report/PojoStackTraceWriter.java | 14 ++++ 5 files changed, 212 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d78376b8/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenersIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenersIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenersIT.java new file mode 100644 index 0000000..cc1bb74 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenersIT.java @@ -0,0 +1,37 @@ +package org.apache.maven.surefire.its; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.Test; + +/** + * Test annotation-based TestNG listener + */ +public class CheckTestNgListenersIT + extends SurefireJUnit4IntegrationTestCase +{ + @Test + public void TestNgListenerReporter() + { + unpack( "testng-listeners" ).mavenTestFailureIgnore( true ).executeTest().assertTestSuiteResults( 1, 0, 1, 0 ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d78376b8/surefire-integration-tests/src/test/resources/testng-listeners/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-listeners/pom.xml b/surefire-integration-tests/src/test/resources/testng-listeners/pom.xml new file mode 100644 index 0000000..e2482a2 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-listeners/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>it-parent</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>testng-listeners</artifactId> + <version>1.0-SNAPSHOT</version> + + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.8.8</version> + </dependency> + </dependencies> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d78376b8/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/MarkAsFailureListener.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/MarkAsFailureListener.java b/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/MarkAsFailureListener.java new file mode 100644 index 0000000..a104604 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/MarkAsFailureListener.java @@ -0,0 +1,83 @@ +package listeners; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +import org.testng.IInvokedMethod; +import org.testng.IInvokedMethodListener; +import org.testng.ITestContext; +import org.testng.ITestListener; +import org.testng.ITestResult; + +/** + * Created by etigwuu on 2014-04-26. + */ +public class MarkAsFailureListener implements ITestListener, IInvokedMethodListener { + + @Override + public void onTestStart(ITestResult result) { + + } + + @Override + public void onTestSuccess(ITestResult result) { + + } + + public static int counter = 0; + /** + * I will be called twice in some condition!!! + * @param result + */ + @Override + public void onTestFailure(ITestResult result) { + System.out.println(++counter); + } + + @Override + public void onTestSkipped(ITestResult result) { + + } + + @Override + public void onTestFailedButWithinSuccessPercentage(ITestResult result) { + + } + + @Override + public void onStart(ITestContext context) { + + } + + @Override + public void onFinish(ITestContext context) { + + } + + @Override + public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { + + } + + @Override + public void afterInvocation(IInvokedMethod method, ITestResult testResult) { + testResult.setStatus(ITestResult.FAILURE); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d78376b8/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/SimpleTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/SimpleTest.java b/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/SimpleTest.java new file mode 100644 index 0000000..f4204a1 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-listeners/src/test/java/listeners/SimpleTest.java @@ -0,0 +1,35 @@ +package listeners; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + +/** + * Created by etigwuu on 2014-04-26. + */ +@Listeners(MarkAsFailureListener.class) +public class SimpleTest { + + @Test + public void test1(){ + System.out.println("Hello world"); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d78376b8/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java index 8e52d68..9c70e6a 100644 --- a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java +++ b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java @@ -57,17 +57,31 @@ public class PojoStackTraceWriter public String smartTrimmedStackTrace() { + if ( t == null ) + { + return ""; + } + SmartStackTraceParser parser = new SmartStackTraceParser( testClass, t, testMethod ); return parser.getString(); } public String writeTrimmedTraceToString() { + if ( t == null ) + { + return ""; + } + return SmartStackTraceParser.innerMostWithFocusOnClass( t, testClass ); } public SafeThrowable getThrowable() { + if ( t == null ) { + return null; + } + return new SafeThrowable( t ); } }