Skip to content

Commit

Permalink
configurable depth on the descriptions used in eclipse, version bump …
Browse files Browse the repository at this point in the history
…and simplified error collation
  • Loading branch information
iantmoore committed Sep 28, 2015
1 parent e23bd73 commit 771a9e9
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Ant/pom.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.technophobia.substeps</groupId>
<artifactId>substeps-runner-parent</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT-SKYBET2</version>
</parent>

<name>SubSteps Ant Runner</name>
Expand Down
2 changes: 1 addition & 1 deletion Common/pom.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.technophobia.substeps</groupId>
<artifactId>substeps-runner-parent</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT-SKYBET2</version>
</parent>

<name>SubSteps Runner Common</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ private String getBuildInfoString(final String msg, final List<List<IExecutionNo
buf.append("\n\n");

IExecutionNode lastNode = failurePath.get(failurePath.size() - 1);
Throwable throwable = lastNode.getResult().getFailure().getCause();

if (throwable != null && throwable.getMessage() != null) {
ThrowableInfo throwableInfo = lastNode.getResult().getFailure().getThrowableInfo();

buf.append(throwable.getMessage() + "\n");
//Throwable throwable = lastNode.getResult().getFailure().getCause();

if (throwableInfo != null && throwableInfo.getMessage() != null) {

buf.append(throwableInfo.getMessage() + "\n");
}

buf.append("Trace:\n\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
package com.technophobia.substeps.runner;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import com.technophobia.substeps.execution.ExecutionResult;
Expand All @@ -40,6 +39,7 @@
*/
public class BuildFailureManagerTest {

// these are referenced via reflection
public void nonFailingMethod() {
System.out.println("no fail");
}
Expand All @@ -49,8 +49,8 @@ public void failingMethod() {
throw new IllegalStateException("that's it, had enough");
}

private RootNode getData() {

private RootNode getCriticalErrorNodeTree(){
Method nonFailMethod = null;
Method failMethod = null;
try {
Expand All @@ -73,45 +73,117 @@ private RootNode getData() {

final Throwable rootFail = new Exception("t1");

rootNode.getResult().setFailed(rootFail);
featureBuilder.getBuilt().getResult().setFailed(rootFail);
scenarioNodeBuilder.getBuilt().getResult().setFailed(rootFail);

SubstepExecutionFailure featureFail = new SubstepExecutionFailure(rootFail, featureBuilder.getBuilt(), ExecutionResult.FAILED);

SubstepExecutionFailure scenarioFailure = new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt(), ExecutionResult.FAILED);

scenarioNodeBuilder.getBuilt().getChildren().get(0).setLine("stepNode1");
SubstepExecutionFailure stepFail = new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt().getChildren().get(0), ExecutionResult.NOT_RUN);

scenarioNodeBuilder.getBuilt().getChildren().get(1).setLine("stepNode2");
scenarioNodeBuilder.getBuilt().getChildren().get(1).getResult().setResult(ExecutionResult.NOT_RUN);
new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt().getChildren().get(1), ExecutionResult.NOT_RUN);

scenarioNodeBuilder.getBuilt().getChildren().get(2).setLine("stepNode3");
scenarioNodeBuilder.getBuilt().getChildren().get(2).getResult().setResult(ExecutionResult.NOT_RUN);
new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt().getChildren().get(2), ExecutionResult.NOT_RUN);

return rootNode;

}

@Test
public void testNonCriticalFailures() {
private RootNode getNonCriticalErrorNodeTree() {

BuildFailureManager bfm = new BuildFailureManager();
Method nonFailMethod = null;
Method failMethod = null;
try {
nonFailMethod = this.getClass().getMethod("nonFailingMethod");
failMethod = this.getClass().getMethod("failingMethod");
} catch (final Exception e) {
Assert.fail(e.getMessage());
}
Assert.assertNotNull(nonFailMethod);
Assert.assertNotNull(failMethod);

TestRootNodeBuilder rootBuilder = new TestRootNodeBuilder();
TestFeatureNodeBuilder featureBuilder = rootBuilder.addFeature(new Feature("test feature", "file")).addTags(
"@can_fail");
TestBasicScenarioNodeBuilder scenarioNodeBuilder = featureBuilder.addBasicScenario("scenarioName")
.addStepImpl(getClass(), nonFailMethod).addStepImpl(getClass(), failMethod)
.addStepImpl(getClass(), nonFailMethod);

RootNode rootNode = rootBuilder.build();

final RootNode rootNode = getData();
// set up the scenario
final Throwable rootFail = new Exception("t1");

final List<SubstepExecutionFailure> failures = new ArrayList<SubstepExecutionFailure>();
SubstepExecutionFailure featureFail = new SubstepExecutionFailure(rootFail, featureBuilder.getBuilt(), ExecutionResult.FAILED);
featureFail.setNonCritical(true);

TestFeatureNodeBuilder featureBuilder = new TestFeatureNodeBuilder(new Feature("test feature", "file"));
SubstepExecutionFailure scenarioFailure = new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt(), ExecutionResult.FAILED);
scenarioFailure.setNonCritical(true);

FeatureNode featureNode = featureBuilder.build();
rootNode.getChildren().add(featureNode);
scenarioNodeBuilder.getBuilt().getChildren().get(0).setLine("stepNode1");
SubstepExecutionFailure stepFail = new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt().getChildren().get(0), ExecutionResult.NOT_RUN);
stepFail.setNonCritical(true);

scenarioNodeBuilder.getBuilt().getChildren().get(1).setLine("stepNode2");
new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt().getChildren().get(1), ExecutionResult.NOT_RUN);

scenarioNodeBuilder.getBuilt().getChildren().get(2).setLine("stepNode3");
new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt().getChildren().get(2), ExecutionResult.NOT_RUN);

return rootNode;
}


private RootNode getBeforesErrorNodeTree(){
Method nonFailMethod = null;
Method failMethod = null;
try {
nonFailMethod = this.getClass().getMethod("nonFailingMethod");
failMethod = this.getClass().getMethod("failingMethod");
} catch (final Exception e) {
Assert.fail(e.getMessage());
}
Assert.assertNotNull(nonFailMethod);
Assert.assertNotNull(failMethod);

TestRootNodeBuilder rootBuilder = new TestRootNodeBuilder();
TestFeatureNodeBuilder featureBuilder = rootBuilder.addFeature(new Feature("test feature", "file")).addTags(
"@can_fail");
TestBasicScenarioNodeBuilder scenarioNodeBuilder = featureBuilder.addBasicScenario("scenarioName")
.addStepImpl(getClass(), nonFailMethod).addStepImpl(getClass(), failMethod)
.addStepImpl(getClass(), nonFailMethod);

RootNode rootNode = rootBuilder.build();

final Throwable rootFail = new Exception("t1");

featureNode.getResult().setFailed(rootFail);
// the setup failure, representing an @BeforeScenario as per AbstractScenarioNodeRunner.runSetup
new SubstepExecutionFailure(rootFail, scenarioNodeBuilder.getBuilt(), true);

final SubstepExecutionFailure f1 = new SubstepExecutionFailure(rootFail, featureNode);
scenarioNodeBuilder.getBuilt().getChildren().get(0).setLine("stepNode1");

f1.setNonCritical(true);
scenarioNodeBuilder.getBuilt().getChildren().get(1).setLine("stepNode2");

failures.add(f1);
scenarioNodeBuilder.getBuilt().getChildren().get(2).setLine("stepNode3");

final Throwable t = new IllegalStateException("No tests executed");

SubstepExecutionFailure sef = new SubstepExecutionFailure(t, rootNode, ExecutionResult.FAILED);

return rootNode;

}




@Test
public void testNonCriticalFailures2() {

BuildFailureManager bfm = new BuildFailureManager();

RootNode rootNode = getNonCriticalErrorNodeTree();

bfm.addExecutionResult(rootNode);

Expand All @@ -120,27 +192,28 @@ public void testNonCriticalFailures() {
Assert.assertTrue(bfm.testSuiteSomeFailures());
Assert.assertFalse(bfm.testSuiteFailed());

// see what happens with an @beforefailure
failures.clear();

failures.add(new SubstepExecutionFailure(rootFail, featureNode, true));
// A critical error
rootNode = getCriticalErrorNodeTree();
bfm = new BuildFailureManager();
bfm.addExecutionResult(rootNode);

// just an @before fail
Assert.assertFalse(bfm.testSuiteCompletelyPassed());
Assert.assertTrue(bfm.testSuiteSomeFailures());
Assert.assertTrue(bfm.testSuiteFailed());

failures.clear();
failures.add(new SubstepExecutionFailure(rootFail, featureNode));

// an @befores error
rootNode = getBeforesErrorNodeTree();
bfm = new BuildFailureManager();
bfm.addExecutionResult(rootNode);

// a normal critical fail
Assert.assertFalse(bfm.testSuiteCompletelyPassed());
Assert.assertTrue(bfm.testSuiteSomeFailures());
Assert.assertTrue(bfm.testSuiteFailed());

}



}
2 changes: 1 addition & 1 deletion Junit/pom.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.technophobia.substeps</groupId>
<artifactId>substeps-runner-parent</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT-SKYBET2</version>
</parent>

<name>SubSteps JUnit Runner</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;

import com.technophobia.substeps.model.Configuration;
import com.technophobia.substeps.runner.description.DescriptionBuilder;
import com.technophobia.substeps.runner.description.DescriptorStatus;
import com.technophobia.substeps.runner.description.JunitVersionedDescriptionBuilder;
Expand All @@ -49,6 +50,12 @@ public class EclipseDescriptionProvider implements DescriptionProvider {

private final DescriptionBuilder descriptionBuilder = new JunitVersionedDescriptionBuilder();

private static final String STEP_DEPTH_KEY = "step.depth.description";

static {
Configuration.INSTANCE.addDefaultProperty(STEP_DEPTH_KEY, Integer.valueOf(5));
}

public Map<Long, Description> buildDescriptionMap(final IExecutionNode rootNode, final Class<?> classContainingTheTests) {
final Description rootDescription = Description.createSuiteDescription(classContainingTheTests);

Expand All @@ -75,7 +82,7 @@ private Description buildDescription(final IExecutionNode node, final Map<Long,

NodeWithChildren<?> nodeWithChildren = (NodeWithChildren<?>) node;

if (nodeWithChildren.hasChildren() && nodeWithChildren.getDepth() < 5) {
if (nodeWithChildren.hasChildren() && nodeWithChildren.getDepth() < Configuration.INSTANCE.getInt(STEP_DEPTH_KEY)) {

for (final IExecutionNode child : nodeWithChildren.getChildren()) {

Expand Down
4 changes: 2 additions & 2 deletions Maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<parent>
<groupId>com.technophobia.substeps</groupId>
<artifactId>substeps-runner-parent</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT-SKYBET2</version>
</parent>

<properties>
<maven.version>2.2.1</maven.version>
</properties>

<description>A maven plugin for substeps BDD framework</description>
<description>A maven plugin for the substeps BDD framework</description>


<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public void init(final int portNumber) throws MojoExecutionException {
this.mbean = MBeanServerInvocationHandler.newProxyInstance(mbsc, objectName, SubstepsServerMBean.class,
false);

// mbsc.addNotificationListener()
//(objectName, this, null, null);


} catch (final IOException e) {

throw new MojoExecutionException("Failed to connect to substeps server", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void addToReport(final RootNode rootNode) {


/**
* @param data
*
* @throws MojoFailureException
*/
private void processBuildData() throws MojoFailureException {
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.technophobia.substeps</groupId>
<artifactId>substeps-runner-parent</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT-SKYBET2</version>
<packaging>pom</packaging>

<!-- for OSS hosting -->
Expand All @@ -21,8 +21,8 @@
</modules>

<properties>
<substeps.core.version>1.1.3-SNAPSHOT</substeps.core.version>
<substeps.api.version>1.1.3-SNAPSHOT</substeps.api.version>
<substeps.core.version>1.1.3-SNAPSHOT-SKYBET3</substeps.core.version>
<substeps.api.version>1.1.3-SNAPSHOT-SKYBET2</substeps.api.version>

<guava.version>10.0</guava.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -195,7 +195,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>substeps-core</artifactId>
<version>${substeps.core.version}</version>
<version>1.1.3-SNAPSHOT-SKYBET1</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down

0 comments on commit 771a9e9

Please sign in to comment.