简体   繁体   English

如何测试Gradle构建脚本

[英]How to test gradle build script

Is there some kind of tool for testing gradle scripts? 有某种工具可以测试gradle脚本吗? Like JUnit is for testing Java code. 像JUnit一样是用于测试Java代码的。
I would like to test my build.gradle script in way to see if it works properly, but would not like to do changes to the development repository (like commiting somethnig, adding test tags and so on). 我想以某种方式测试我的build.gradle脚本,以查看其是否正常运行,但不希望对开发存储库进行更改(例如提交somethnig,添加测试标签等)。

Is there a way to do such thing, in lets call it, "transaction" manner, as if to do changes, see if it is doing as I intended and then rollback it. 有一种方法可以做这种事情,以“交易”的方式进行,就像进行更改一样,看看它是否按照我的预期进行,然后回滚。

Or do you recommend to mock my repository and all other needed data (something like staging only for my build script testing) and then do my things there? 还是建议您模拟我的存储库和所有其他所需的数据(例如仅在进行构建脚本测试时进行登台),然后在那做我的事情?
What is the best practice for doing this? 最佳做法是什么?

Please take into consideration that I am gradle newbie. 请考虑到我是新手。 :) :)

Thanks in advance for any kind of advice/help. 在此先感谢您提供任何建议/帮助。
mismas mismas

There is no single purpose tool for this. 没有为此目的的单一工具。 OTOH there are various possibilities how to test your code. OTOH有多种测试代码的可能性。 If your build logic is in buildSrc project - http://www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:build_sources - you can put your testing code there. 如果你的构建逻辑是buildSrc项目- http://www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:build_sources -你可以在那里把你的测试代码。 Of course you have to decide how to test your code to avoid interaction like repository changes. 当然,您必须决定如何测试代码,以避免诸如存储库更改之类的交互。

You can take a look at Gradle codebase. 您可以看一下Gradle代码库。 There are plenty of integration tests where you can find ideas. 有很多集成测试可在其中找到想法。 Aside from unittest it is likely you will want to use Gradle Tooling API to control build started from your tests. 除了单元测试,您可能还想使用Gradle Tooling API来控制从测试开始的构建。

较新版本的Gradle随TestKit一起提供

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM