[英]How to make Eclipse recognize folders as “code folders” when a project is imported?
我有一個Maven Java項目,我在其中添加了pom:
<build>
....
<plugin>
<!-- adding second test source directory (just for integration tests) -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${plugin.build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integration-test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</build>
InteliJ將我在兼容測試下的java和資源文件夾識別為代碼文件夾,但Eclipse沒有。 有沒有辦法在導入項目時將這些文件夾添加為代碼文件夾?
嘗試右鍵單擊Project Explorer
的文件夾,在上下文菜單中選擇Build Path
選項,然后在選擇Build Path
后出現的菜單中單擊Use as Source Folder
。
我建議不要在Maven中使用自己的目錄布局,因為這會導致很多問題,你總是需要配置它。 堅持標准。
src/test/java
。 此時您不必配置任何內容,默認情況下會采用此路徑。 IT*.java
和單元測試UT*.java
。 maven-surefire-plugin
執行單元測試和maven-failsafe-plugin
執行的集成測試。 您可以定義用於標識測試類的文件名模式。 您還可以創建僅運行UT或僅運行IT的配置文件。
<project> <!-- ... --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.13</version> <configuration> <includes> <include>**/UT*.java</include> </includes> <excludes> <exclude>**/IT*.java</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.18</version> <configuration> <includes> <include>**/IT*.java</include> </includes> </configuration> <executions> <execution> <id>failsafe-integration-tests</id> <phase>integration-test</phase> <goals> <goal>integration-test</goal> </goals> </execution> </executions> </plugin>
進一步閱讀: http : //tomaszdziurko.pl/2013/01/running-unit-tests-integration-tests-separately-maven-testng/
還有一篇關於正確使用集成測試的有趣文章:http: //zeroturnaround.com/rebellabs/the-correct-way-to-use-integration-tests-in-your-build-process/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.