Skip to content
This repository

Realtime Test Reporting Support for TeamCity #536

Closed
wants to merge 6 commits into from

2 participants

Alexander Ilyin Sebastian Bergmann
Alexander Ilyin

Just tested on TeamCity Professional 7.0.1 (build 21326)
phpunit (with this file in include path) should be run like this: phpunit --printer PHPUnit_Framework_TeamCity_TestListener

So I want to share this feature.

Alexander Ilyin

Just find that it can be also provided in XML configuration and maybe if you'll accept pull request listener should be moved to Extensions namespace?

Sebastian Bergmann sebastianbergmann closed this April 09, 2012
Sebastian Bergmann

I do not want to add new test/ticket listeners etc. to the base package. Your listener should go into a separate package that can be optionally installed. Have a look at https://github.com/sebastianbergmann/phpunit-ticketlistener-jira or https://github.com/sebastianbergmann/phpunit-testlistener-xhprof

Alexander Ilyin

Right, thx for advice.

Alexander Ilyin

Is there any plugins listings where I have to add new one?

Alexander Ilyin

Thx, but where 3rd parties extensions should be listed? For example if I have one and it's available as PEAR package now, where I should add it?

Sebastian Bergmann

There is no other place where additional packages are listed (yet). Feel free to fork the phpunit-documentation repository and add your package there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
155  PHPUnit/Framework/TeamCity/TestListener.php
... ...
@@ -0,0 +1,155 @@
  1
+<?php
  2
+/**
  3
+ * @author Alexander Ilyin
  4
+ * @url    http://confluence.jetbrains.net/display/TCD7/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests
  5
+ */
  6
+class PHPUnit_Framework_TeamCity_TestListener extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
  7
+{
  8
+    /**
  9
+     * An error occurred.
  10
+     *
  11
+     * @todo Add check that $test is instance of PHPUnit_Framework_TestCase
  12
+     *
  13
+     * @param  PHPUnit_Framework_Test $test
  14
+     * @param  Exception              $e
  15
+     * @param  float                  $time
  16
+     */
  17
+    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
  18
+    {
  19
+        $message = sprintf("##teamcity[testFailed name='%s' message='%s' details='%s']" . PHP_EOL,
  20
+            addslashes($test->getName()),
  21
+            addslashes($e->getMessage()),
  22
+            addslashes($e->getTraceAsString())
  23
+        );
  24
+        $this->write($message);
  25
+    }
  26
+
  27
+    /**
  28
+     * A failure occurred.
  29
+     *
  30
+     * @todo Add check that $test is instance of PHPUnit_Framework_TestCase
  31
+     *
  32
+     * @param  PHPUnit_Framework_Test                 $test
  33
+     * @param  PHPUnit_Framework_AssertionFailedError $e
  34
+     * @param  float                                  $time
  35
+     */
  36
+    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
  37
+    {
  38
+        $testResult = $test->getTestResultObject();
  39
+        /** @var $failure PHPUnit_Framework_TestFailure */
  40
+        foreach ($testResult->failures() as $failure) {
  41
+            /** @var $exception PHPUnit_Framework_ExpectationFailedException */
  42
+            $exception         = $failure->thrownException();
  43
+            $comparisonFailure = $exception->getComparisonFailure();
  44
+            $message           = sprintf("##teamcity[testFailed type='comparisonFailure' name='%s' message='%s' details='%s' expected='%s' actual='%s']" . PHP_EOL,
  45
+                addslashes($test->getName()),
  46
+                addslashes($e->getMessage()),
  47
+                addslashes($e->getTraceAsString()),
  48
+                addslashes($comparisonFailure->getExpectedAsString()),
  49
+                addslashes($comparisonFailure->getActualAsString())
  50
+            );
  51
+            $this->write($message);
  52
+        }
  53
+    }
  54
+
  55
+    /**
  56
+     * Incomplete test.
  57
+     *
  58
+     * @todo Add check that $test is instance of PHPUnit_Framework_TestCase
  59
+     *
  60
+     * @param  PHPUnit_Framework_Test $test
  61
+     * @param  Exception              $e
  62
+     * @param  float                  $time
  63
+     */
  64
+    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  65
+    {
  66
+        $message = sprintf("##teamcity[testIgnored name='%s' message='%s']" . PHP_EOL,
  67
+            addslashes($test->getName()),
  68
+            addslashes($e->getMessage())
  69
+        );
  70
+        $this->write($message);
  71
+    }
  72
+
  73
+    /**
  74
+     * Skipped test.
  75
+     *
  76
+     * @todo   Add check that $test is instance of PHPUnit_Framework_TestCase
  77
+     *
  78
+     * @param  PHPUnit_Framework_Test $test
  79
+     * @param  Exception              $e
  80
+     * @param  float                  $time
  81
+     *
  82
+     * @since  Method available since Release 3.0.0
  83
+     */
  84
+    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  85
+    {
  86
+        $message = sprintf("##teamcity[testIgnored name='%s' message='%s']" . PHP_EOL,
  87
+            addslashes($test->getName()),
  88
+            addslashes($e->getMessage())
  89
+        );
  90
+        $this->write($message);
  91
+    }
  92
+
  93
+    /**
  94
+     * A test suite started.
  95
+     *
  96
+     * @param  PHPUnit_Framework_TestSuite $suite
  97
+     *
  98
+     * @since  Method available since Release 2.2.0
  99
+     */
  100
+    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
  101
+    {
  102
+        $message = sprintf("##teamcity[testSuiteStarted name='%s']" . PHP_EOL,
  103
+            addslashes($suite->getName())
  104
+        );
  105
+        $this->write($message);
  106
+    }
  107
+
  108
+    /**
  109
+     * A test suite ended.
  110
+     *
  111
+     * @param  PHPUnit_Framework_TestSuite $suite
  112
+     *
  113
+     * @since  Method available since Release 2.2.0
  114
+     */
  115
+    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
  116
+    {
  117
+        $message = sprintf("##teamcity[testSuiteFinished name='%s']" . PHP_EOL,
  118
+            addslashes($suite->getName())
  119
+        );
  120
+        $this->write($message);
  121
+    }
  122
+
  123
+    /**
  124
+     * A test started.
  125
+     *
  126
+     * @todo Add check that $test is instance of PHPUnit_Framework_TestCase
  127
+     *
  128
+     * @param  PHPUnit_Framework_Test $test
  129
+     */
  130
+    public function startTest(PHPUnit_Framework_Test $test)
  131
+    {
  132
+        $message = sprintf("##teamcity[testStarted name='%s' captureStandardOutput='%s']" . PHP_EOL,
  133
+            addslashes($test->getName()),
  134
+            'true'
  135
+        );
  136
+        $this->write($message);
  137
+    }
  138
+
  139
+    /**
  140
+     * A test ended.
  141
+     *
  142
+     * @todo Add check that $test is instance of PHPUnit_Framework_TestCase
  143
+     *
  144
+     * @param  PHPUnit_Framework_Test     $test
  145
+     * @param  float                      $time
  146
+     */
  147
+    public function endTest(PHPUnit_Framework_Test $test, $time)
  148
+    {
  149
+        $message = sprintf("##teamcity[testFinished name='%s' duration='%s']" . PHP_EOL,
  150
+            addslashes($test->getName()),
  151
+            $time
  152
+        );
  153
+        $this->write($message);
  154
+    }
  155
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.