Skip to content

Commit ea36f66

Browse files
Update sitedocs for branch main
1 parent 24ac2ca commit ea36f66

File tree

1 file changed

+94
-1
lines changed

1 file changed

+94
-1
lines changed

doc/main/TestingBundles.html

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,100 @@ <h3>junit-platform mojo</h3>
307307
<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>
308308
</ul></section></section><section><a id="combining_different_approaches"></a>
309309
<h2>combining different approaches</h2></section><section><a id="setup_test_source_folders_in_eclipse"></a>
310-
<h2>setup test source folders in eclipse</h2></section></section> </main>
310+
<h2>setup test source folders in eclipse</h2>
311+
<p>When working with Eclipse and PDE (Plugin Development Environment), you can mark source folders as containing test sources. This is important for Tycho to correctly identify and compile test classes separately from production code.</p><section><a id="Marking_a_Source_Folder_as_Test_Source"></a>
312+
<h3>Marking a Source Folder as Test Source</h3>
313+
<p>To configure a source folder to contain test sources in Eclipse:</p>
314+
<ol style="list-style-type: decimal;">
315+
316+
<li><strong>Right-click on your Eclipse plugin project</strong> in the Package Explorer or Project Explorer</li>
317+
<li><strong>Select &#x201c;Properties&#x201d;</strong> from the context menu</li>
318+
<li><strong>Navigate to &#x201c;Java Build Path&#x201d;</strong> in the left panel</li>
319+
<li><strong>Select the &#x201c;Source&#x201d; tab</strong></li>
320+
<li><strong>Locate the source folder</strong> you want to mark as a test source folder (e.g., <code>src_test</code>)</li>
321+
<li><strong>Expand the source folder entry</strong> by clicking on the arrow/triangle next to it to reveal its attributes</li>
322+
<li><strong>Look for &#x201c;Contains test sources: No&#x201d;</strong> in the expanded view</li>
323+
<li><strong>Double-click on &#x201c;Contains test sources: No&#x201d;</strong> or select it and click &#x201c;Edit&#x201d;</li>
324+
<li><strong>In the dialog that appears, change the value to &#x201c;Yes&#x201d;</strong></li>
325+
<li><strong>Click &#x201c;OK&#x201d;</strong> to close the edit dialog</li>
326+
<li><strong>Click &#x201c;Apply and Close&#x201d;</strong> to save the changes</li>
327+
</ol>
328+
<blockquote>
329+
330+
<p><strong>Tip</strong>: After marking a source folder as a test source, you'll see &#x201c;Contains test sources: Yes&#x201d; in the build path configuration.</p>
331+
</blockquote></section><section><a id="What_This_Does"></a>
332+
<h3>What This Does</h3>
333+
<p>When you mark a source folder as containing test sources, Eclipse modifies the <code>.classpath</code> file in your project to include a test attribute. For example:</p>
334+
335+
<pre class="prettyprint linenums"><code class="language-xml">&lt;classpathentry kind=&quot;src&quot; output=&quot;bin_test&quot; path=&quot;src_test&quot;&gt;
336+
&lt;attributes&gt;
337+
&lt;attribute name=&quot;test&quot; value=&quot;true&quot;/&gt;
338+
&lt;/attributes&gt;
339+
&lt;/classpathentry&gt;
340+
</code></pre></section><section><a id="How_Tycho_Uses_This_Information"></a>
341+
<h3>How Tycho Uses This Information</h3>
342+
<p>Tycho reads the <code>.classpath</code> file to determine which source folders contain test code:</p>
343+
<ul>
344+
345+
<li><strong>Source folders without the test attribute</strong> (or with <code>test=&quot;false&quot;</code>) are treated as production code and compiled during the <code>compile</code> phase</li>
346+
<li><strong>Source folders with <code>test=&quot;true&quot;</code></strong> are treated as test code and compiled during the <code>test-compile</code> phase with test dependencies available</li>
347+
</ul>
348+
<p>This allows you to:</p>
349+
<ul>
350+
351+
<li>Keep test and production code in the same project</li>
352+
<li>Use different output directories for test and production classes</li>
353+
<li>Have test-specific dependencies that don't leak into your production bundle</li>
354+
</ul></section><section><a id="Recommended_Directory_Structure"></a>
355+
<h3>Recommended Directory Structure</h3>
356+
<p>For projects that include both production and test code, a common structure is:</p>
357+
358+
<pre><code class="nohighlight nocode">your-plugin-project/
359+
&#x251c;&#x2500;&#x2500; src/ (production code)
360+
&#x251c;&#x2500;&#x2500; src_test/ (test code, marked with test=&quot;true&quot;)
361+
&#x251c;&#x2500;&#x2500; META-INF/
362+
&#x2502; &#x2514;&#x2500;&#x2500; MANIFEST.MF
363+
&#x251c;&#x2500;&#x2500; build.properties
364+
&#x2514;&#x2500;&#x2500; pom.xml
365+
</code></pre></section><section><a id="Important_Notes"></a>
366+
<h3>Important Notes</h3>
367+
<ul>
368+
369+
<li>The test attribute is supported in Eclipse since version 4.8 (2018-09)</li>
370+
<li>When using pomless builds, Tycho automatically detects test source folders marked in the <code>.classpath</code> file</li>
371+
<li>Test source folders should be included in the <code>build.properties</code> file if you want them to be part of the build</li>
372+
<li>Make sure your <code>pom.xml</code> includes the necessary test plugin configurations (either <code>maven-surefire-plugin</code> or <code>tycho-surefire-plugin</code> with appropriate executions)</li>
373+
</ul></section><section><a id="Alternative.3A_Manual_.classpath_Editing"></a>
374+
<h3>Alternative: Manual .classpath Editing</h3>
375+
<p>If you prefer, you can also directly edit the <code>.classpath</code> file in your project root. Add or modify the <code>classpathentry</code> element for your test source folder to include the test attribute:</p>
376+
377+
<pre class="prettyprint linenums"><code class="language-xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
378+
&lt;classpath&gt;
379+
&lt;!-- Production source folder --&gt;
380+
&lt;classpathentry kind=&quot;src&quot; output=&quot;bin&quot; path=&quot;src&quot;/&gt;
381+
382+
&lt;!-- Test source folder with test attribute --&gt;
383+
&lt;classpathentry kind=&quot;src&quot; output=&quot;bin_test&quot; path=&quot;src_test&quot;&gt;
384+
&lt;attributes&gt;
385+
&lt;attribute name=&quot;test&quot; value=&quot;true&quot;/&gt;
386+
&lt;/attributes&gt;
387+
&lt;/classpathentry&gt;
388+
389+
&lt;!-- Other classpath entries --&gt;
390+
&lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot;/&gt;
391+
&lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.pde.core.requiredPlugins&quot;/&gt;
392+
&lt;classpathentry kind=&quot;output&quot; path=&quot;bin&quot;/&gt;
393+
&lt;/classpath&gt;
394+
</code></pre>
395+
<p>After editing, refresh your project in Eclipse (F5) for the changes to take effect.</p></section><section><a id="Example_Projects"></a>
396+
<h3>Example Projects</h3>
397+
<p>See these demo projects for working examples:</p>
398+
<ul>
399+
400+
<li><a href="https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/surefire/with-source-folder" class="externalLink">Surefire with source folder</a> - Shows <code>src_test</code> marked as test source</li>
401+
<li><a href="https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/tycho/standalone/test" class="externalLink">Tycho standalone test</a> - Shows a project with only test sources</li>
402+
<li><a href="https://github.com/eclipse-tycho/tycho/tree/master/demo/testing/tycho/osgitest" class="externalLink">Tycho OSGi test</a> - Shows mixed production and test sources</li>
403+
</ul></section></section></section> </main>
311404
</div>
312405
</div>
313406
<hr/>

0 commit comments

Comments
 (0)