Eclipse 中 maven 工程添加 test 源文件
1. 背景
在 Eclipse 的 maven 工程中,我们会看到 test 文件夹是黑色的:
有时候,如果我们 src/java 文件夹下面没有任何文件,使用 git push 的时候,远程仓库不会创建这个文件夹,那么我们 pull 下来的时候也不会有这个文件,下面会介绍如何创建 test 文件。
2. 创建 test 源文件
- 右键工程 > Build Path > Config Build Path > Source > Add Folder
- 选中 test 文件夹下的 java 和 resources,如果不存在,则自己 create New Folder
- 编辑 src/test/java 和 src/test/resources 的 Output folder:
- Edit 对话框中指定 target\test-classes 即可,两个源文件夹都要改。
- 设置 Contains test sources,点击按钮 Toggle 即可,将它切换成 Yes,那么目录就变成黑色了。
- 这样,就能还原 maven 工程的源文件夹了