Govan
Govan

Reputation: 2129

Shall I add my unit test folder to the java build path in Eclipse?

We are developing an Eclipse product made of several plugins, some of them developed by us. Each of our plugins has be defined as an Eclipse plugin project in workspace and has two folders, source and test. Recently I noticed that we are delivering the test classes to the user like the our source classes. Now I want to remove the test classes from the result of our product. Shall I remove the test folder from the Java build path (see the attachment)? And what else I should do to don't deploy our tests to the end-user?

enter image description here

To build the project we are using the eclipse standard ant script to create our zip file. I don't find where can I exclude test files. Here is the the Ant script:

<property name="allElementsFile" value="${eclipse.pdebuild.scripts}/productBuild/allElements.xml"/>
<import file="${eclipse.pdebuild.scripts}/build.xml"/>
<property name="pluginPath" value=""/>
<property name="pluginList" value=""/>
<property name="featureList" value=""/>
<property name="includeLaunchers" value="true"/>
<property name="generatedBuildProperties" value=""/>
<condition property="nestedInclusions" value="true">
    <istrue value="${p2.gathering}" />
</condition>

<!-- ===================================================================== -->
<!-- main entry point to setup, fetch, generate, build etc. Use -->
<!-- the customTargets.xml to modify the build behaviour. -->
<!-- ===================================================================== -->
<target name="main" description="the main build target">    
    <antcall target="preBuild" />
    <antcall target="processRepos"/>
    <antcall target="generateFeature"> <!-- Generate the feature to drive the fetch -->
        <param name="verify" value="false"/>
    </antcall>
    <antcall target="fetch" />
    <antcall target="generateFeature"> <!-- We are calling generate feature a second time so that we can get the pack / unpack clause fixed -->
        <param name="verify" value="true"/>
    </antcall> 
    <antcall target="generate" /> 
    <antcall target="process" /> 
    <antcall target="assemble" />
    <antcall target="package" />
    <antcall target="postBuild" />
</target>

<!-- ===================================================================== -->
<!-- Generate a container feature based on the product file                -->
<!-- The plugin or feature containing the .product file will need to exist -->
<!-- already, use preSetup or postSetup to fetch it if necessary           -->
<!-- ===================================================================== -->
<target name="generateFeature">
    <eclipse.generateFeature
        featureId="org.eclipse.pde.build.container.feature"
        buildDirectory="${buildDirectory}"
        baseLocation="${baseLocation}"
        productFile="${product}"
        verify="${verify}"
        pluginPath="${transformedRepoLocation}${path.separator}${pluginPath}"
        configInfo="${configs}"
        pluginList="${pluginList}"
        featureList="${featureList}"
        includeLaunchers="${includeLaunchers}"
        buildPropertiesFile="${generatedBuildProperties}"
        nestedInclusions="${nestedInclusions}"
        filterP2Base="${filterP2Base}"
    />
</target>


</project>

Upvotes: 3

Views: 2748

Answers (2)

Govan
Govan

Reputation: 2129

To remove test files (if you defined for every plugin project a source folder and a test folder) from the code while building a pde project using pde ant scripts you should remove the test folder from the build.properties of that project. The build.properties is a part of plugin.xml

Upvotes: 0

Christophe Roussy
Christophe Roussy

Reputation: 16999

This is an issue with your deployment procedure/script. Are you using Eclipse to build the jar ? It should not have to do with the build path, you should keep your test source in the build path if you use Eclipse to code them. Usually a deployment procedure using Ant or Maven will exclude the test classes from the result (jar, war, ...). It is also advisable to automatically run the tests before the jar is created.

Upvotes: 1

Related Questions