I am looking for gunit that is in similar lines to JUnit to test grade scripts e.g I want to write a gradel script outcome before testing to be ready with resources in a particular directory etc…
e.g before test tasks about to run its first test, I want to make sure all these files are in these directories
If these files does not exist, I wish to fail the test task to say pre-conditions are not met…
Today lack fo such test, I had to waste 5 hours…
In much advanced test, I want also check if each of the file has the right content to make sure basic level corruption did not happen etc…
That way testing build script itself can be too handy more so if it follows JUnit style testing way
I was trying testkit, but that looks heavy and it will run same grade script that has invoked test task again as another process.
What I am looking for
when I have build.gradle.kts
gradle test -DselfTest
-DselfTest etc… is some flag to say, run associated BuildScript TestCases, and each test case would be like JUnit 5 Test Case, and each test would not have the gradle test context i.e. no more additional reading of build.gradle.kts, that is current running gradle tasks reference is given to each test method so that we can now write the test code by running each task and verify it the way we need.
Looks bit complex, but may be worth it… in large scale gradle script testing.
Actually, if you have such complex logic in a build script, that you need to test it, it is a strong sign you should refactor the whole thing and move the logic into custom plugins (be them binary plugins or precompiled script plugins doesn’t matter).
An idiomatic build script should practically be only declarative and not contain logic.
The logic should be encapsulated in custom tasks and plugins.
These custom tasks and plugins that you then have in an included build, or in
buildSrc have the full possibilities of a build. You can write tests to test the logic and so on. And TestKit is indeed the way to go if you want to do functional / integration tests. For unit tests the
ProjectBuilder might be enough.
Any good starter example to understand this further…