Skip to content
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,22 @@ You can use variables in FILENAME.

See [the test-case example](src/test/resources/selenese/testcase_include.html).

Tests in DRAFT mode
-------------------

Sometimes tests exist before the application-under-test has completely
implemented the feature being tested (in Test-Driven-Development, for
example). You can mark such tests to be in DRAFT (as opposed to FINAL)
mode, whereby they are executed normally and their results are shown.
But for build purposes, they will be accounted as "skipped" rather than
"success" or "fail" - thereby allowing builds including them to succeed.

This is done by way of a ###-tagged "lifecycle" directive in a comment:

<!-- ### lifecycle=DRAFT ### -->

The default lifecycle state is FINAL.

License
-------

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/jp/vmi/junit/result/ITestTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
*/
public interface ITestTarget {

/**
* Selenese lifecycle types.
*/
@SuppressWarnings("javadoc")
public enum Lifecycle {
FINAL, DRAFT
}

/**
* Flag for triggering LIFECYCLE_DRAFT in a selenese test.
*/
public static final String FLAG_LIFECYCLE_DRAFT = "### lifecycle=" + Lifecycle.DRAFT.name() + " ###";

/**
* Get test-target file base name.
*
Expand Down Expand Up @@ -36,4 +49,18 @@ public interface ITestTarget {
* @return stop watch.
*/
StopWatch getStopWatch();

/**
* Get the lifecycle type.
*
* @return lifecycle type.
*/
Lifecycle getLifecycle();

/**
* Set the lifecycle type.
*
* @param lifecycle
*/
void setLifecycle(Lifecycle lifecycle);
}
20 changes: 13 additions & 7 deletions src/main/java/jp/vmi/junit/result/JUnitResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jp.vmi.junit.result.ITestTarget.Lifecycle;
import jp.vmi.selenium.selenese.utils.CommandLineUtils;

import static jp.vmi.junit.result.ObjectFactory.*;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void startTestSuite(ITestSuite testSuite) {
/**
* End test-suite.
*
* @param testSuite test-suite instatnce.
* @param testSuite test-suite instance.
*/
public void endTestSuite(ITestSuite testSuite) {
TestSuiteResult suiteResult = (TestSuiteResult) map.remove(testSuite);
Expand All @@ -125,7 +126,7 @@ public void endTestSuite(ITestSuite testSuite) {
/**
* Add property in test-suite.
*
* @param testSuite test-suite instatnce.
* @param testSuite test-suite instance.
* @param name property name.
* @param value property value.
*/
Expand Down Expand Up @@ -166,7 +167,8 @@ public void endTestCase(ITestCase testCase) {
public void setSuccess(ITestCase testCase) {
TestCaseResult caseResult = (TestCaseResult) map.get(testCase);
caseResult.setSuccess();
failsafeSummary.completed++;
if (testCase.getLifecycle() != Lifecycle.DRAFT)
failsafeSummary.completed++;
}

/**
Expand All @@ -179,8 +181,10 @@ public void setSuccess(ITestCase testCase) {
public void setError(ITestCase testCase, String message, String trace) {
TestCaseResult caseResult = (TestCaseResult) map.get(testCase);
caseResult.setError(message, trace);
failsafeSummary.completed++;
failsafeSummary.errors++;
if (testCase.getLifecycle() != Lifecycle.DRAFT) {
failsafeSummary.completed++;
failsafeSummary.errors++;
}
}

/**
Expand All @@ -193,8 +197,10 @@ public void setError(ITestCase testCase, String message, String trace) {
public void setFailure(ITestCase testCase, String message, String trace) {
TestCaseResult caseResult = (TestCaseResult) map.get(testCase);
caseResult.setFailure(message, trace);
failsafeSummary.completed++;
failsafeSummary.failures++;
if (testCase.getLifecycle() != Lifecycle.DRAFT) {
failsafeSummary.completed++;
failsafeSummary.failures++;
}
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/jp/vmi/junit/result/TestCaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.apache.commons.lang3.StringUtils;

import jp.vmi.junit.result.ITestTarget.Lifecycle;
import jp.vmi.selenium.selenese.utils.LogRecorder.LogMessage;

import static jp.vmi.junit.result.ObjectFactory.*;
Expand Down Expand Up @@ -44,7 +45,8 @@ public class TestCaseResult extends TestResult<ITestCase> {
* Set success result.
*/
public void setSuccess() {
this.success = true;
if (this.testTarget.getLifecycle() != Lifecycle.DRAFT)
this.success = true;
}

/**
Expand All @@ -54,7 +56,8 @@ public void setSuccess() {
* @param value error value.
*/
public void setError(String message, String value) {
error = factory.createError(message, value);
if (this.testTarget.getLifecycle() != Lifecycle.DRAFT)
error = factory.createError(message, value);
}

/**
Expand All @@ -64,7 +67,8 @@ public void setError(String message, String value) {
* @param value failure value.
*/
public void setFailure(String message, String value) {
failure = factory.createFailure(message, value);
if (this.testTarget.getLifecycle() != Lifecycle.DRAFT)
failure = factory.createFailure(message, value);
}

/**
Expand Down Expand Up @@ -93,7 +97,7 @@ public int getFailures() {
@XmlElementRef
@XmlJavaTypeAdapter(SkippedAdapter.class)
public Integer getSkipped() {
return (!success && error == null && failure == null) ? 1 : 0;
return ((this.testTarget.getLifecycle() == Lifecycle.DRAFT) || (!success && error == null && failure == null)) ? 1 : 0;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/jp/vmi/selenium/selenese/ErrorTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class ErrorTestCase extends ErrorSource implements ITestCase, IHtmlResultTestCase {

private LogRecorder logRecorder = null;
private Lifecycle lifecycle = Lifecycle.FINAL;

@Override
public void setLogRecorder(LogRecorder logRecorder) {
Expand All @@ -35,6 +36,16 @@ public Type getType() {
return Type.TEST_CASE;
}

@Override
public Lifecycle getLifecycle() {
return lifecycle;
}

@Override
public void setLifecycle(Lifecycle lifecycle) {
this.lifecycle = lifecycle;
}

@ExecuteTestCase
@Override
public Result execute(Selenese parent, Context context) throws InvalidSeleneseException {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/jp/vmi/selenium/selenese/ErrorTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ErrorTestSuite extends ErrorSource implements ITreedFileGenerator,

private ITreedFileGenerator parent = null;
private int index = 0;
private Lifecycle lifecycle = Lifecycle.FINAL;

@Override
public ErrorTestSuite initialize(String filename, InvalidSeleneseException e) {
Expand All @@ -23,6 +24,16 @@ public Type getType() {
return Type.TEST_SUITE;
}

@Override
public Lifecycle getLifecycle() {
return lifecycle;
}

@Override
public void setLifecycle(Lifecycle lifecycle) {
this.lifecycle = lifecycle;
}

@Override
public ITreedFileGenerator getParent() {
return parent;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/jp/vmi/selenium/selenese/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class TestCase implements Selenese, ITestCase, IHtmlResultTestCase {
private final StopWatch stopWatch = new StopWatch();
private LogRecorder logRecorder = null;

private Lifecycle lifecycle = Lifecycle.FINAL;

/**
* Initialize after constructed.
*
Expand Down Expand Up @@ -74,6 +76,16 @@ public Type getType() {
return Type.TEST_CASE;
}

@Override
public Lifecycle getLifecycle() {
return lifecycle;
}

@Override
public void setLifecycle(Lifecycle lifecycle) {
this.lifecycle = lifecycle;
}

/**
* Test-case source type.
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/jp/vmi/selenium/selenese/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class TestSuite implements Selenese, ITreedFileGenerator, ITestSuite, IHt
private final StopWatch stopWatch = new StopWatch();
private Result result = UNEXECUTED;

private Lifecycle lifecycle = Lifecycle.FINAL;

/**
* Initialize after constructed.
*
Expand Down Expand Up @@ -78,6 +80,16 @@ public Type getType() {
return Type.TEST_SUITE;
}

@Override
public Lifecycle getLifecycle() {
return lifecycle;
}

@Override
public void setLifecycle(Lifecycle lifecycle) {
this.lifecycle = lifecycle;
}

@Override
public boolean isError() {
return false;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/jp/vmi/selenium/selenese/command/Comment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package jp.vmi.selenium.selenese.command;

import jp.vmi.junit.result.ITestTarget;
import jp.vmi.junit.result.ITestTarget.Lifecycle;
import jp.vmi.selenium.selenese.Context;
import jp.vmi.selenium.selenese.result.Result;

Expand Down Expand Up @@ -28,6 +30,11 @@ public boolean mayUpdateScreen() {

@Override
protected Result executeImpl(Context context, String... curArgs) {
// if a comment contains FLAG_LIFECYCLE_DRAFT, set this testcase to DRAFT
String comment = getArguments()[MESSAGE];
if (comment.contains(ITestTarget.FLAG_LIFECYCLE_DRAFT)) {
context.getCurrentTestCase().setLifecycle(Lifecycle.DRAFT);
}
return SUCCESS;
}

Expand Down
Loading