Skip to content

Commit

Permalink
Merge pull request #6 from telekom/feature/updated-tt2
Browse files Browse the repository at this point in the history
Updated to final release of Testerra 2
  • Loading branch information
martingrossmann authored Jun 28, 2022
2 parents 2a7b14b + 54a0eb8 commit 7ca35b3
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 40 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TeamCity Connector

<p align="center">
<a href="https://mvnrepository.com/artifact/io.testerra/teamcity-connector" title="MavenCentral"><img src="https://img.shields.io/maven-central/v/io.testerra/teamcity-connector/1?label=Maven%20Central"></a>
<a href="https://mvnrepository.com/artifact/io.testerra/teamcity-connector" title="MavenCentral"><img src="https://img.shields.io/maven-central/v/io.testerra/teamcity-connector/2?label=Maven%20Central"></a>
<a href="/../../commits/" title="Last Commit"><img src="https://img.shields.io/github/last-commit/telekom/testerra-teamcity-connector?style=flat"></a>
<a href="/../../issues" title="Open Issues"><img src="https://img.shields.io/github/issues/telekom/testerra-teamcity-connector?style=flat"></a>
<a href="./LICENSE" title="License"><img src="https://img.shields.io/badge/License-Apache%202.0-green.svg?style=flat"></a>
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -53,7 +54,7 @@ Maven:
<dependency>
<groupId>io.testerra</groupId>
<artifactId>teamcity-connector</artifactId>
<version>2.0-RC-2</version>
<version>2.0</version>
</dependency>
````

Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <p>
* Date: 07.05.2020
* Time: 09:40
* This tests should results as follows:
* <p>
* *** 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<String> 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']"));

}

}
7 changes: 3 additions & 4 deletions src/test/resources/test.properties
Original file line number Diff line number Diff line change
@@ -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
tt.runcfg=tcc-test

tt.failed.tests.if.throwable.messages=testT05_RetriedTestSecondRunPassed

0 comments on commit 7ca35b3

Please sign in to comment.