Skip to content

Should work for cucumber scenario outlines #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/main/java/com/novocode/junit/EventDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private abstract class InfoEvent extends Event {
public void testAssumptionFailure(final Failure failure)
{
uncapture(true);
postIfFirst(new ErrorEvent(failure, Status.Skipped) {
post(new ErrorEvent(failure, Status.Skipped) {
void logTo(RichLogger logger) {
logger.warn("Test assumption in test "+ansiName+" failed: "+ansiMsg + durationSuffix());
}
Expand All @@ -72,7 +72,7 @@ void logTo(RichLogger logger) {
public void testFailure(final Failure failure)
{
uncapture(true);
postIfFirst(new ErrorEvent(failure, Status.Failure) {
post(new ErrorEvent(failure, Status.Failure) {
void logTo(RichLogger logger) {
logger.error("Test "+ansiName+" failed: "+ansiMsg + durationSuffix(), error);
}
Expand All @@ -83,7 +83,7 @@ void logTo(RichLogger logger) {
public void testFinished(Description desc)
{
uncapture(false);
postIfFirst(new InfoEvent(desc, Status.Success) {
post(new InfoEvent(desc, Status.Success) {
void logTo(RichLogger logger) {
logger.debug("Test "+ansiName+" finished" + durationSuffix());
}
Expand All @@ -94,7 +94,7 @@ void logTo(RichLogger logger) {
@Override
public void testIgnored(Description desc)
{
postIfFirst(new InfoEvent(desc, Status.Skipped) {
post(new InfoEvent(desc, Status.Skipped) {
void logTo(RichLogger logger) {
logger.info("Test "+ansiName+" ignored");
}
Expand Down Expand Up @@ -148,12 +148,6 @@ void logTo(RichLogger logger) {
});
}

private void postIfFirst(AbstractEvent e)
{
e.logTo(logger);
if(reported.add(e.fullyQualifiedName())) handler.handle(e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported now goes unused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractEvent should probably expose Description, and reported should use the description's identity to track whether the event has been posted or not.

}

void post(AbstractEvent e)
{
e.logTo(logger);
Expand Down
19 changes: 19 additions & 0 deletions src/sbt-test/cucumber/scenario_outlines/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name := "cucumber-test"

organization := "com.waioeka.sbt"

version := "0.0.4"

scalaVersion := "2.12.2"

libraryDependencies ++= Seq (
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"io.cucumber" % "cucumber-core" % "2.0.0" % "test",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a transitive dependency of cucumber-scala and not required.

"io.cucumber" %% "cucumber-scala" % "2.0.0" % "test",
Copy link

@mpkorstanje mpkorstanje Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"io.cucumber" % "cucumber-jvm" % "2.0.0" % "test",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pom dependency and not required.

"io.cucumber" % "cucumber-junit" % "2.0.0" % "test",
"com.novocode" % "junit-interface" % sys.props("project.version") % "test")

def before() : Unit = { println("beforeAll") }
def after() : Unit = { println("afterAll") }

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@my-tag
Feature: Multiplication
In order to avoid making mistakes
As a dummy
I want to multiply numbers

Scenario Outline: Multiply two variables
Given a variable x with value <x>
And a variable y with value <y>
When I multiply x * y
Then I get <z>
Examples:
| x | y | z |
| 1 | 1 | 1 |
| 2 | 3 | 1 |

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2015, Michael Lewis
* All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems problematic. If we're doing Lightbend CLA the copy right needs to transfer to Lightbend.

*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.waioeka.sbt

import cucumber.api.scala.{ScalaDsl, EN}
import org.scalatest.Matchers


/**
* AddAndMultiplySteps
*
*/
class MultiplicationSteps extends ScalaDsl with EN with Matchers {
var x : Int = 0
var y : Int = 0
var z : Int = 0


Given("""^a variable x with value (\d+)$""") { (arg0: Int) =>
x = arg0
}

Given("""^a variable y with value (\d+)$""") { (arg0: Int) =>
y = arg0
}

When("""^I multiply x \* y$""") { () =>
z = x * y
}

Then("""^I get (\d+)$""") { (arg0: Int) =>
z should be (arg0)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cucumber

import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith

@RunWith(classOf[Cucumber])
@CucumberOptions(
features = Array("classpath:features"),
glue = Array("com.waioeka.sbt"),
strict = true,
)
class CucumberApplicationSpec

2 changes: 2 additions & 0 deletions src/sbt-test/cucumber/scenario_outlines/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# run the cucumber tests and see them fail
-> test