# How to create a gradle test suite without using built-in frameworks

**URL:** <https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230>\
**Category:** Help/Discuss\
**Created:** [June 29, 2022, 8:22am UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230 "2022-06-29T08:22:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [June 29, 2022, 8:22am UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/1 "2022-06-29T08:22:36Z")

</div>

Lets say I created a new and unique Java test framework, or I am retro-fitting a legacy project where the tests are just `main(String[] args)`-entrypoint classes and I would like to run those with `gradle test` and have gradle exit with 0 if none of the tests fail/nothing throws.

“without built-in frameworks” - meaning, without [useJUnit()](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:useJUnit()), [useJUnitPlatform()](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:useJUnitPlatform()) et al.

Any guidance for this use case? I also posted on [stack overflow](https://stackoverflow.com/q/72428334).

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [June 29, 2022, 12:32pm UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/2 "2022-06-29T12:32:21Z")

</div>

Create a task that iterates over the classes and calls their `main` methods, then make `test` depend on that task.  
If it really needs to be the `test` task that should do it, register a `doLast` action on the `test` task that does the same logic.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [June 29, 2022, 12:34pm UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/3 "2022-06-29T12:34:15Z")

</div>

Or you could also implement a custom JUnit platform engine that discovers your tests and executes them.  
This way you can even get an test report out of it and any integration like IDE, CI server, and others that are compatible to JUnit 5 platform can actually see your tests as tests.  
Shouldn’t be too complex for such a specific case where you can make some assumptions.

---

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [July 19, 2022, 8:50pm UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/4 "2022-07-19T20:50:35Z")

</div>

The idea of a custom JUnit engine seems the most appropriate, I had not even thought of implementing the solution in that layer. I must say I’m still very curious what the “Test” type task does in gradle and how i can take advantage of it, but this will probably be a valid solution for my use case.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 20, 2022, 9:33am UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/5 "2022-07-20T09:33:13Z")

</div>

When you have your custom JUnit engine, you still use the `Test` type task.  
Your custom JUnit engine still runs on JUnit platform and thus you get the integration like runability from IDE, integration in CI servers, HTML report generated by Gradle and so on.  
So you would still call `useJUnitPlatform()` for the task and then your custom engine will find tests and all is well.

---

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [July 20, 2022, 10:24am UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/6 "2022-07-20T10:24:10Z")

</div>

yeah I’m well aware of that, but seeing as its also used for JUnit 4 and TestNG, which are probably totally unlike JUnit 5, there probably has to be some kind of undocumented internal API (or spi) that neatly abstracts some of these details in a useful way.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 28, 2022, 5:30pm UTC](https://discuss.gradle.org/t/how-to-create-a-gradle-test-suite-without-using-built-in-frameworks/43230/7 "2022-07-28T17:30:11Z")

</div>

Probably, but why should you care?  
Especially if you do it with a custom JUnit platform
