aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/output/TextTestWriter.java
diff options
context:
space:
mode:
authorJ08nY2017-11-05 16:48:30 +0100
committerJ08nY2017-11-05 16:48:30 +0100
commitdaaa7abd91ff8ae12e0b1835045489acbda0539f (patch)
tree1a2a944473285359a9af3691f2ce69b608264f12 /src/cz/crcs/ectester/reader/output/TextTestWriter.java
parent16f20afbff36a7e048d24d7e7d1db8657f002c5e (diff)
downloadECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.tar.gz
ECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.tar.zst
ECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.zip
Implement Result.ExpectedValue to add more logic to test evaluation.
- Introduces a new enum Result.ExpectedValue, which is used to signify what Test results are expected. - Changes the Result.Value enum to contain information about what was expected. It gains more values: - UXSUCCESS -> Unexpected success. - XFAILURE -> Expected failure. The values SUCCESS and XFAILURE are the OK, values. - Creates a hierarchy of evaluating Responses, Simple tests and Compoung tests. Simple test evaluates the OK property of the response object (using .successfull() method) and again exposes its OK property which depends on the tests ExpectedValue and the response success. Compound test evaluates the OK property of the Simple tests it contains (using the .ok() method) and again exposes its OK property which depends on the concrete Compound test variant, but involves some ExpectedValues and the success of the individual Simple tests it contains.
Diffstat (limited to 'src/cz/crcs/ectester/reader/output/TextTestWriter.java')
-rw-r--r--src/cz/crcs/ectester/reader/output/TextTestWriter.java50
1 files changed, 34 insertions, 16 deletions
diff --git a/src/cz/crcs/ectester/reader/output/TextTestWriter.java b/src/cz/crcs/ectester/reader/output/TextTestWriter.java
index dedefe6..d697761 100644
--- a/src/cz/crcs/ectester/reader/output/TextTestWriter.java
+++ b/src/cz/crcs/ectester/reader/output/TextTestWriter.java
@@ -1,7 +1,6 @@
package cz.crcs.ectester.reader.output;
import cz.crcs.ectester.reader.test.Test;
-import cz.crcs.ectester.reader.test.Result;
import cz.crcs.ectester.reader.test.TestSuite;
import java.io.PrintStream;
@@ -13,6 +12,8 @@ public class TextTestWriter implements TestWriter {
private PrintStream output;
private ResponseWriter respWriter;
+ public static int BASE_WIDTH = 72;
+
public TextTestWriter(PrintStream output) {
this.output = output;
this.respWriter = new ResponseWriter(output);
@@ -24,34 +25,51 @@ public class TextTestWriter implements TestWriter {
output.println("=== " + suite.getDescription());
}
- private String testPrefix(Test t) {
- return String.format("%-4s", t.getResultValue() == Result.Value.SUCCESS ? "OK" : "NOK");
- }
- private String testString(Test t) {
- if (!t.hasRun())
+ private String testString(Test t, int offset) {
+ if (!t.hasRun()) {
return null;
+ }
StringBuilder out = new StringBuilder();
if (t instanceof Test.Simple) {
Test.Simple test = (Test.Simple) t;
- out.append(String.format("%-70s:", testPrefix(t) + " : " + test.getDescription())).append(" : ");
+ out.append(test.ok() ? "OK " : "NOK ");
+ out.append("━ ");
+ int width = BASE_WIDTH - (offset + out.length());
+ String widthSpec = "%-" + String.valueOf(width) + "s";
+ out.append(String.format(widthSpec, t.getDescription()));
+ out.append(" ┃ ");
+ out.append(String.format("%-9s", test.getResultValue().name()));
+ out.append(" ┃ ");
out.append(respWriter.responseSuffix(test.getResponse()));
- } else if (t instanceof Test.Compound) {
+ } else {
+ out.append(System.lineSeparator());
Test.Compound test = (Test.Compound) t;
+ out.append(test.ok() ? "OK " : "NOK ");
+ out.append("┳ ");
+ int width = BASE_WIDTH - (offset + out.length());
+ String widthSpec = "%-" + String.valueOf(width) + "s";
+ out.append(String.format(widthSpec, t.getDescription()));
+ out.append(" ┃ ");
+ out.append(String.format("%-9s", test.getResultValue().name()));
+ out.append(" ┃ ");
+ out.append(test.getResultCause());
+ out.append(System.lineSeparator());
Test[] tests = test.getTests();
for (int i = 0; i < tests.length; ++i) {
- if (i == 0) {
- out.append(" /- ");
- } else if (i == tests.length - 1) {
- out.append(" \\- ");
+ if (i == tests.length - 1) {
+ out.append(" ┗ ");
} else {
- out.append(" | ");
+ out.append(" ┣ ");
+ }
+ out.append(testString(tests[i], offset + 6));
+ if (i != tests.length - 1) {
+ out.append(System.lineSeparator());
}
- out.append(testString(tests[i])).append(System.lineSeparator());
}
- out.append(String.format("%-70s", testPrefix(t) + " : " + test.getDescription()));
}
+
return out.toString();
}
@@ -59,7 +77,7 @@ public class TextTestWriter implements TestWriter {
public void outputTest(Test t) {
if (!t.hasRun())
return;
- output.println(testString(t));
+ output.println(testString(t, 0));
output.flush();
}