diff --git a/README.md b/README.md
index 011c4d9..87a0a0d 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# TeamCity Connector
-
+
@@ -35,6 +35,7 @@ It will register automatically by using the Testerra ModuleHook.
| `1.0` | `1.0.0..1.8` |
| `1.1` | `1.9` |
| `2.0-RC-2` | `>= 2.0-RC-19` |
+| `2.0` | `>= 2.0` |
### Usage
@@ -43,7 +44,7 @@ Include the following dependency in your project.
Gradle:
````groovy
-implementation 'io.testerra:teamcity-connector:2.0-RC-2'
+implementation 'io.testerra:teamcity-connector:2.0'
````
Maven:
@@ -53,7 +54,7 @@ Maven:
io.testerra
teamcity-connector
- 2.0-RC-2
+ 2.0
````
diff --git a/build.gradle b/build.gradle
index f4e7298..04cc727 100644
--- a/build.gradle
+++ b/build.gradle
@@ -9,7 +9,7 @@ apply plugin: 'io.codearte.nexus-staging'
ext {
// Minimum required Testerra version
- testerraCompileVersion = '2-SNAPSHOT'
+ testerraCompileVersion = '2.0'
// Unit tests use the latest Testerra version
testerraTestVersion = '[2,3-SNAPSHOT)'
moduleVersion = '2-SNAPSHOT'
@@ -28,6 +28,9 @@ dependencies {
compileOnly 'io.testerra:driver-ui-desktop:' + testerraCompileVersion
testImplementation 'io.testerra:driver-ui-desktop:' + testerraTestVersion
+ testImplementation 'io.testerra:report-ng:' + testerraTestVersion
+ // Capture System.out.println
+ testImplementation 'io.github.hakky54:consolecaptor:1.0.2'
}
test {
diff --git a/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/hooks/TeamCityHook.java b/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/hooks/TeamCityHook.java
index 809005d..0cb481a 100644
--- a/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/hooks/TeamCityHook.java
+++ b/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/hooks/TeamCityHook.java
@@ -20,8 +20,8 @@
import com.google.inject.AbstractModule;
import eu.tsystems.mms.tic.testerra.plugins.teamcity.listener.TeamCityEventListener;
import eu.tsystems.mms.tic.testerra.plugins.teamcity.worker.TeamCityStatusReportWorker;
+import eu.tsystems.mms.tic.testframework.common.Testerra;
import eu.tsystems.mms.tic.testframework.hooks.ModuleHook;
-import eu.tsystems.mms.tic.testframework.report.TesterraListener;
/**
* Registering Workers for pushing status messages to teamcity while running a testerra test job
@@ -36,7 +36,7 @@ public class TeamCityHook extends AbstractModule implements ModuleHook {
@Override
public void init() {
- EventBus eventBus = TesterraListener.getEventBus();
+ EventBus eventBus = Testerra.getEventBus();
eventBus.register(new TeamCityEventListener());
eventBus.register(new TeamCityStatusReportWorker());
}
diff --git a/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/listener/TeamCityEventListener.java b/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/listener/TeamCityEventListener.java
index b0e9540..f49c516 100644
--- a/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/listener/TeamCityEventListener.java
+++ b/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/listener/TeamCityEventListener.java
@@ -19,10 +19,16 @@
package eu.tsystems.mms.tic.testerra.plugins.teamcity.listener;
import com.google.common.eventbus.Subscribe;
+
import static eu.tsystems.mms.tic.testframework.report.utils.ExecutionContextController.getCurrentExecutionContext;
+
import eu.tsystems.mms.tic.testerra.plugins.teamcity.TeamCityMessagePusher;
+import eu.tsystems.mms.tic.testframework.common.Testerra;
import eu.tsystems.mms.tic.testframework.events.TestStatusUpdateEvent;
+import eu.tsystems.mms.tic.testframework.report.ITestStatusController;
import eu.tsystems.mms.tic.testframework.report.TesterraListener;
+import eu.tsystems.mms.tic.testframework.report.model.context.RunConfig;
+import eu.tsystems.mms.tic.testframework.report.utils.IExecutionContextController;
import org.apache.commons.lang3.StringUtils;
/**
@@ -40,15 +46,17 @@ public class TeamCityEventListener implements TestStatusUpdateEvent.Listener {
@Override
@Subscribe
public void onTestStatusUpdate(TestStatusUpdateEvent event) {
- String counterInfoMessage = TesterraListener.getTestStatusController().getCounterInfoMessage();
+ ITestStatusController statusController = Testerra.getInjector().getInstance(ITestStatusController.class);
+ IExecutionContextController executionContextController = Testerra.getInjector().getInstance(IExecutionContextController.class);
+
+ String counterInfoMessage = statusController.getCounterInfoMessage();
if (StringUtils.isBlank(counterInfoMessage)) {
counterInfoMessage = "Running";
}
- final String teamCityMessage =
- getCurrentExecutionContext().runConfig.getReportName() + " " + getCurrentExecutionContext().runConfig.RUNCFG + ": " +
- counterInfoMessage;
+ RunConfig runConfig = executionContextController.getExecutionContext().getRunConfig();
+ final String teamCityMessage = runConfig.getReportName() + " " + runConfig.RUNCFG + ": " + counterInfoMessage;
messagePusher.updateProgressMessage(teamCityMessage);
}
}
diff --git a/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/worker/TeamCityStatusReportWorker.java b/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/worker/TeamCityStatusReportWorker.java
index 80685a4..60528a1 100644
--- a/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/worker/TeamCityStatusReportWorker.java
+++ b/src/main/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/worker/TeamCityStatusReportWorker.java
@@ -24,8 +24,8 @@
import eu.tsystems.mms.tic.testframework.events.ExecutionFinishEvent;
import eu.tsystems.mms.tic.testframework.report.FailureCorridor;
import eu.tsystems.mms.tic.testframework.report.ITestStatusController;
-import eu.tsystems.mms.tic.testframework.report.TesterraListener;
-import eu.tsystems.mms.tic.testframework.report.utils.ExecutionContextController;
+import eu.tsystems.mms.tic.testframework.report.model.context.RunConfig;
+import eu.tsystems.mms.tic.testframework.report.utils.IExecutionContextController;
/**
* Reports global build status to teamcity
@@ -43,11 +43,11 @@ public class TeamCityStatusReportWorker implements ExecutionFinishEvent.Listener
@Override
@Subscribe
public void onExecutionFinish(ExecutionFinishEvent event) {
- ITestStatusController testStatusController = TesterraListener.getTestStatusController();
+ ITestStatusController statusController = Testerra.getInjector().getInstance(ITestStatusController.class);
+ RunConfig runConfig = Testerra.getInjector().getInstance(IExecutionContextController.class).getExecutionContext().getRunConfig();
- String statusMessage = ExecutionContextController.getCurrentExecutionContext().runConfig.getReportName() + " " +
- ExecutionContextController.getCurrentExecutionContext().runConfig.RUNCFG + ": ";
- statusMessage += testStatusController.getCounterInfoMessage() + " ";
+ String statusMessage = runConfig.getReportName() + " " + runConfig.RUNCFG + ": ";
+ statusMessage += statusController.getCounterInfoMessage() + " ";
// There is a difference in build status depending on failure corridor active
// If corridor is active, we have to get these values and if corridor matches, we report a success
@@ -60,7 +60,7 @@ public void onExecutionFinish(ExecutionFinishEvent event) {
messagePusher.updateBuildStatus(TeamCityBuildStatus.FAILURE, statusMessage, false);
}
} else {
- if (testStatusController.getTestsFailed() == 0) {
+ if (statusController.getTestsFailed() == 0) {
messagePusher.updateBuildStatus(TeamCityBuildStatus.SUCCESS, statusMessage, false);
} else {
messagePusher.updateBuildStatus(TeamCityBuildStatus.FAILURE, statusMessage, false);
diff --git a/src/test/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/test/SimpleTest.java b/src/test/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/test/SimpleTest.java
index 53a5cc3..252c20a 100644
--- a/src/test/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/test/SimpleTest.java
+++ b/src/test/java/eu/tsystems/mms/tic/testerra/plugins/teamcity/test/SimpleTest.java
@@ -12,59 +12,106 @@
* limitations under the License.
*
* Contributors:
- * Eric Kubenka
+ * Martin Großmann
*/
package eu.tsystems.mms.tic.testerra.plugins.teamcity.test;
import eu.tsystems.mms.tic.testframework.annotations.Fails;
-import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import eu.tsystems.mms.tic.testframework.testing.TesterraTest;
import eu.tsystems.mms.tic.testframework.utils.TimerUtils;
+import nl.altindag.console.ConsoleCaptor;
import org.testng.Assert;
+import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
/**
* Simple Tests for validating teamcity progess pushers
*
- * Date: 07.05.2020
- * Time: 09:40
+ * This tests should results as follows:
+ *
+ * *** Stats: Test Methods Count: 8 (7 relevant)
+ * *** Stats: Failed: 1
+ * *** Stats: Retried: 1
+ * *** Stats: Expected Failed: 1
+ * *** Stats: Skipped: 1
+ * *** Stats: Passed: 4 ? Recovered: 1
*
- * @author Eric Kubenka
+ * @author Martin Großmann
*/
public class SimpleTest extends TesterraTest {
- private static final int TEST_DURATION = 10_000;
- private static final boolean FAIL_TESTS = PropertyManager.getBooleanProperty("test.execution.fail.tests", true);
- private static final boolean FAIL_EXPECTED_TESTS = PropertyManager.getBooleanProperty("test.execution.fail.expected.tests", true);
+ private static final int TEST_DURATION = 1_000;
+
+ private static ConsoleCaptor consoleCaptor;
+
+ @BeforeSuite
+ public void beforeSuite() {
+ consoleCaptor = new ConsoleCaptor();
+ }
- @Test
+ @Test(priority = 1)
public void testT01_SimplePassedTest() {
TimerUtils.sleep(TEST_DURATION);
Assert.assertTrue(true);
}
- @Test
+ @Test(priority = 2)
public void testT02_SimplePassedTest() {
TimerUtils.sleep(TEST_DURATION);
Assert.assertTrue(true);
}
- @Test
+ @Test(priority = 3)
public void testT03_SimpleFailedTest() {
TimerUtils.sleep(TEST_DURATION);
- if (FAIL_TESTS) {
- Assert.fail("Failing for reasons");
- }
+ Assert.fail("Failing for reasons");
+ }
+
+ @Test(dependsOnMethods = {"testT03_SimpleFailedTest"}, priority = 4)
+ public void testT04_SkippedTest() {
+ TimerUtils.sleep(TEST_DURATION);
+ Assert.assertTrue(true);
}
- @Test
- @Fails(ticketId = 1, description = "Failing for reasons")
- public void testT04_SimpleExpectedFailedTest() {
+ @Test(priority = 5)
+ @Fails(ticketString = "ticket1", description = "Failing for reasons")
+ public void testT05_SimpleExpectedFailedTest() {
TimerUtils.sleep(TEST_DURATION);
- if (FAIL_EXPECTED_TESTS) {
- Assert.fail("Failing for reasons...");
+ Assert.fail("Failing for reasons...");
+ }
+
+ AtomicInteger counter = new AtomicInteger(0);
+
+ @Test(priority = 6)
+ public void testT06_RetriedTestSecondRunPassed() {
+ this.counter.incrementAndGet();
+ if (counter.get() == 1) {
+ // Message is already defined in test.properties
+ Assert.assertTrue(false, "testT05_RetriedTestSecondRunPassed");
+ } else {
+ Assert.assertTrue(true);
}
+
+ }
+
+ @Test(priority = 999)
+ public void test07_VerifyTeamCityMessages() {
+ List standardOutput = consoleCaptor.getStandardOutput();
+
+ // Assert all printed TeamCity messages
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: Running']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 1 Passed']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 2 Passed']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 1 Failed, 2 Passed']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 1 Failed, 1 Skipped, 2 Passed']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 1 Failed, 1 Expected Failed, 1 Skipped, 2 Passed']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 1 Retried, 1 Failed, 1 Expected Failed, 1 Skipped, 2 Passed']"));
+ Assert.assertTrue(standardOutput.contains("##teamcity[progressMessage 'Test report tcc-test: 1 Retried, 1 Failed, 1 Expected Failed, 1 Skipped, 3 Passed']"));
+
}
}
diff --git a/src/test/resources/test.properties b/src/test/resources/test.properties
index efb3a3c..428dca2 100644
--- a/src/test/resources/test.properties
+++ b/src/test/resources/test.properties
@@ -1,4 +1,3 @@
-tt.failure.corridor.active=false
-tt.failure.corridor.allowed.failed.tests=0
-test.execution.fail.tests=true
-test.execution.fail.expected.tests=true
\ No newline at end of file
+tt.runcfg=tcc-test
+
+tt.failed.tests.if.throwable.messages=testT05_RetriedTestSecondRunPassed