Skip to content

Commit

Permalink
Backport fix of #138 to 0.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Oct 6, 2015
1 parent b108e5e commit b99383b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.8.4

## Fixed Issues

* Fixed in issue with TestNG introduced with v0.8.3 that a failing case does not lead to failed TestNG status [#138](https://github.com/TNG/JGiven/issues/138)

# v0.8.3

## Fixed Issues
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ task wrapper(type: Wrapper) {

allprojects {
group = 'com.tngtech.jgiven'
version = '0.8.3'
version = '0.8.4'
apply plugin: 'jacoco'
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void testFinished( ITestResult paramITestResult ) {
scenario.finished();
} catch( Throwable throwable ) {
paramITestResult.setThrowable( throwable );
paramITestResult.setStatus( ITestResult.FAILURE );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public void the_test_passes() {
assertThat( result.getFailureCount() ).as( "failure count" ).isEqualTo( 0 );
}

public SELF $_tests_fail( int nFailedTests ) {
assertThat( result.getFailureCount() ).isEqualTo( nFailedTests );
return self();
}

public SELF the_test_fails() {
assertThat( result.getFailureCount() ).as( "failure count" ).isGreaterThan( 0 );
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class DataProviderTestNgTest extends JGivenScenarioTest<GivenScenarioTest
public void a_scenario_with_one_failing_case_still_executes_the_following_ones() {
given().a_TestNG_test_with_two_cases_and_the_first_one_fails();
when().the_test_class_is_executed_with( TestFramework.TestNG );
then().the_report_model_contains_one_scenario_with_$_cases( 2 )
then().$_tests_fail( 1 )
.and().the_report_model_contains_one_scenario_with_$_cases( 2 )
.and().the_scenario_has_execution_status( ExecutionStatus.FAILED )
.and().case_$_has_status( 1, ExecutionStatus.FAILED )
.and().case_$_has_status( 2, ExecutionStatus.SUCCESS );
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package com.tngtech.jgiven.testng;

import com.tngtech.jgiven.testframework.TestExecutionResult;
import java.util.List;

import org.testng.ITestResult;

import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.tngtech.jgiven.testframework.TestExecutionResult;

public class TestNgExecutionResult extends TestExecutionResult {

public ITestResult testResult;
public List<ITestResult> testResults;

@Override
public int getFailureCount() {
return testResult.getStatus() == ITestResult.FAILURE ? 1 : 0;
return FluentIterable.from( testResults ).filter( new Predicate<ITestResult>() {
@Override
public boolean apply( ITestResult input ) {
return input.getStatus() == ITestResult.FAILURE;
}
} ).size();
}

@Override
public String getFailureMessage( int i ) {
return testResult.getThrowable().getMessage();
return testResults.get( i ).getThrowable().getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.tngtech.jgiven.testng;

import com.tngtech.jgiven.testframework.TestExecutionResult;
import com.tngtech.jgiven.testframework.TestExecutor;
import java.util.List;

import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.TestNG;

import com.beust.jcommander.internal.Lists;
import com.tngtech.jgiven.base.ScenarioTestBase;
import com.tngtech.jgiven.impl.Config;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.testframework.TestExecutionResult;
import com.tngtech.jgiven.testframework.TestExecutor;

public class TestNgExecutor extends TestExecutor {

Expand All @@ -30,7 +33,7 @@ public TestExecutionResult execute( Class<?> testClass, String testMethod ) {
testng.run();
Config.config().setReportEnabled( true );
result.reportModel = testListenerAdapter.reportModel;
result.testResult = testListenerAdapter.testResult;
result.testResults = testListenerAdapter.testResults;
return result;
}

Expand All @@ -41,7 +44,7 @@ public TestExecutionResult execute( Class<?> testClass ) {

static class ScenarioTestListenerAdapter extends TestListenerAdapter {
ReportModel reportModel;
ITestResult testResult;
List<ITestResult> testResults = Lists.newArrayList();

@Override
public void onTestSuccess( ITestResult tr ) {
Expand All @@ -65,7 +68,7 @@ public void onStart( ITestContext testContext ) {
}

private void setTestResult( ITestResult tr ) {
testResult = tr;
testResults.add( tr );
reportModel = ( (ScenarioTestBase<?, ?, ?>) tr.getInstance() ).getScenario().getModel();
}
}
Expand Down

0 comments on commit b99383b

Please sign in to comment.