|
58 | 58 | </ul></li> |
59 | 59 | <li class="active"><a><span class="icon-chevron-down"></span>Testing Bundles</a> |
60 | 60 | <ul class="nav nav-list"> |
| 61 | + <li><a href="tycho-test-plugin/plugin-info.html">Tycho Test Plugin</a></li> |
61 | 62 | <li><a href="tycho-surefire-plugin/plugin-info.html">Tycho Surefire Plugin</a></li> |
62 | 63 | </ul></li> |
63 | 64 | <li><a href="TychoCiFriendly.html">Tycho CI Friendly Versions</a></li> |
@@ -231,7 +232,78 @@ <h2>bnd-testing</h2> |
231 | 232 | to automatically inject services:</p></li> |
232 | 233 | <li> |
233 | 234 | <p><a href="https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/bnd/osgi-test" class="externalLink">https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/bnd/osgi-test</a></p></li> |
234 | | -</ul></section><section><a id="combining_different_approaches"></a> |
| 235 | +</ul></section><section><a id="tycho-test-plugin"></a> |
| 236 | +<h2>tycho-test-plugin</h2> |
| 237 | +<p>The <a href="https://tycho.eclipseprojects.io/doc/master/tycho-test-plugin/plugin-info.html" class="externalLink">tycho-test-plugin</a> is a new plugin introduced in Tycho 6 to provide unified testing of OSGi bundles. |
| 238 | +Unlike previous approaches, it is no longer bound to surefire and offers better integration with modern testing frameworks.</p><section><a id="junit-platform_mojo"></a> |
| 239 | +<h3>junit-platform mojo</h3> |
| 240 | +<p>The <code>tycho-test:junit-platform</code> mojo integrates the <a href="https://docs.junit.org/current/user-guide/#running-tests-console-launcher" class="externalLink">JUnit Platform Console Launcher</a> into any OSGi Framework. |
| 241 | +This approach has several advantages:</p> |
| 242 | +<ol style="list-style-type: decimal;"> |
| 243 | + |
| 244 | +<li>Tycho is completely independent from the used JUnit framework version (since it calls it via a command-line interface)</li> |
| 245 | +<li>Better and more natural integration of selecting test engines in the pom.xml or with the target platform</li> |
| 246 | +<li>You can use any of the JUnit provided test engines or new features that might be added</li> |
| 247 | +</ol> |
| 248 | +<p>This requires:</p> |
| 249 | +<ul> |
| 250 | + |
| 251 | +<li>packaging <code>eclipse-plugin</code> is used</li> |
| 252 | +<li>a configured execution of the <code>tycho-test:junit-platform</code> goal</li> |
| 253 | +<li>JUnit Platform dependencies (console launcher and test engines) as test-scoped dependencies</li> |
| 254 | +</ul> |
| 255 | +<p>A sample snippet looks like this:</p> |
| 256 | + |
| 257 | +<pre class="prettyprint linenums"><code class="language-xml"><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 258 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> |
| 259 | + ... |
| 260 | + <build> |
| 261 | + ... |
| 262 | + <plugin> |
| 263 | + <groupId>org.eclipse.tycho</groupId> |
| 264 | + <artifactId>tycho-test-plugin</artifactId> |
| 265 | + <version>${tycho-version}</version> |
| 266 | + <executions> |
| 267 | + <execution> |
| 268 | + <id>execute-tests</id> |
| 269 | + <goals> |
| 270 | + <goal>junit-platform</goal> |
| 271 | + </goals> |
| 272 | + </execution> |
| 273 | + </executions> |
| 274 | + </plugin> |
| 275 | + </build> |
| 276 | + |
| 277 | + <dependencies> |
| 278 | + <!-- The API is used at compile time of the bundle --> |
| 279 | + <dependency> |
| 280 | + <groupId>org.junit.jupiter</groupId> |
| 281 | + <artifactId>junit-jupiter-api</artifactId> |
| 282 | + <version>${junit-version}</version> |
| 283 | + <scope>compile</scope> |
| 284 | + </dependency> |
| 285 | + |
| 286 | + <!-- The console and the engine are only required at test execution time --> |
| 287 | + <dependency> |
| 288 | + <groupId>org.junit.platform</groupId> |
| 289 | + <artifactId>junit-platform-console</artifactId> |
| 290 | + <version>${junit-version}</version> |
| 291 | + <scope>test</scope> |
| 292 | + </dependency> |
| 293 | + <dependency> |
| 294 | + <groupId>org.junit.jupiter</groupId> |
| 295 | + <artifactId>junit-jupiter-engine</artifactId> |
| 296 | + <version>${junit-version}</version> |
| 297 | + <scope>test</scope> |
| 298 | + </dependency> |
| 299 | + </dependencies> |
| 300 | +</project> |
| 301 | +</code></pre> |
| 302 | +<p>To execute the tests, one has to invoke maven with <code>mvn verify</code>. The following demo project is provided as an example:</p> |
| 303 | +<ul> |
| 304 | + |
| 305 | +<li><a href="https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/junit-platform" class="externalLink">https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/junit-platform</a></li> |
| 306 | +</ul></section></section><section><a id="combining_different_approaches"></a> |
235 | 307 | <h2>combining different approaches</h2></section><section><a id="setup_test_source_folders_in_eclipse"></a> |
236 | 308 | <h2>setup test source folders in eclipse</h2></section></section> </main> |
237 | 309 | </div> |
|
0 commit comments