使用 Gradle API,我尝试创建一个包含示例文件的项目。我尝试制作的插件应该在文件夹中制作 java 接口(interface)。
@Test
public void pluginCreatesFiles() {
Project project = ProjectBuilder.builder().withProjectDir(new File(testDir, "example")).build() //Build project with Example.java
project.pluginManager.apply 'solar.dimensions.orbit' //Apply the plugin
assertTrue(new File(project.getRootDir(), "src/main/java/solar/dimensions/api").exists()); //Does the file exist?
}
我将我的 gradle 插件与 Example.java
一起应用并测试以查看应创建的文件夹是否存在。如何获取 testDir
?
最佳答案
您必须自己设置该目录。 junit 测试中的最佳方法是使用临时文件夹规则:
@Rule
public TemporaryFolder myfolder = new TemporaryFolder();
@Test
public void pluginCreatesFiles() {
def projectDir = new File(myfolder.newFolder("folder"), "example")
Project project = ProjectBuilder.builder().withProjectDir(projectDir).build() //Build project with Example.java
project.pluginManager.apply 'solar.dimensions.orbit' //Apply the plugin
assertTrue(new File(project.getRootDir(), "src/main/java/solar/dimensions/api").exists()); //Does the file exist?
}
关于java - 制作包含测试文件的 Gradle 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30902003/