In our last Gilded Rose episode ( • Gradle Build Refactoring - Extract Subproject ) we found out how to divide a monolithic Gradle build into subprojects. Our motivation is to speed up our build by only running tests that might have been broken by our changes.
Partitioning a project is an art, with the ideal boundaries between subprojects depending on the structure of our code and tests, team topologies, and the vagaries of our build tool.
In this episode we will try to separate our browser tests into their own subproject. On the way, we’ll learn about the difference between Gradle api and implementation dependencies, and how the test fixture plugin allows us to share test code between modules.
Duncan continues his series on optimizing the Gilded Rose project's Gradle build by focusing on reorganizing the testing framework. The objective is to separate browser tests into their own subproject to reduce build times by only running necessary tests. Duncan begins by reverting previous changes and then details the process of creating a new 'testApp' Gradle submodule. He explains the intricacies of Gradle API and implementation dependencies, the use of the TestFixture plugin, and the creation of test fixtures. The session includes multiple code refactorings, dependency adjustments, and detailed troubleshooting. The ultimate goal is to reduce interdependencies within the project while ensuring that all tests run efficiently. Duncan hints at future plans to create a convention plugin to manage shared configuration and further optimize the build process.
00:00:41 Undoing the previous partitioning
00:01:59 This time we are going to skim our browser tests off the top
00:02:52 Creating a new sub-project
00:04:39 Try to move a browser test
00:05:35 We can't move the test because it depends on other code in the /src/test
00:06:15 Move it instead into testFixtures
00:08:58 Mikado-Method our way to the smallest set of code to be moved
00:12:28 Sanity check and commit
00:13:35 Now work our way out
00:16:38 Once they are in testFixtures, we can move the tests into test-app
00:19:21 Now garbage collect our dependencies
There is a playlist of TDD Gilded Rose episodes - • Test Driven Gilded Rose in Kotlin
and one for Gradle • Gradle
If you are going to be at KotlinConf 2025, or even just in Copenhagen in May, then you should sign up for the workshop that Nat Pryce and I are running. It’s called Refactoring to Functional Kotlin, and will give you hands-on experience of taking legacy code and safely migrating it to a functional style. Places are limited, so buy now at https://kotlinconf.com/workhops
I get lots of questions about the test progress bar. It was written by the inimitable @dmitrykandalov. To use it install his Liveplugin (https://plugins.jetbrains.com/plugin/...) and then this gist https://gist.github.com/dmcg/1f56ac39...
If you like this video, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.