The road to Quarkus 2.0: continuous testing
According to the InfoQ 2020 Java Trends Report, Quarkus has grown in popularity, quickly entering the early adopters space. The frame called Supersonic, subatomic Java, added more features to facilitate the development and operation of software applications. In the 17 months since the release of Quarkus 1.0, its Development mode added state-preserving hot deployment and redeployment features and now aims to add yet another Ruby-inspired feature. Quarkus 2.0 will offer developers the possibility to run tests continuously whenever a class is changed. This feature promises to work well behind the scenes, warning the developer if new code will interrupt testing.
InfoQ spoke to Stuart douglas, Senior Principal Engineer at Red Hat, for a better understanding of this promising feature.
InfoQ: What was the motivation for implementing continuous testing? What benefits do you think this will bring to the development process?
Stuart Douglas: It actually came about because of a question on the mailing list of a developer who mainly develops in Ruby, but was trying out Java. He said he liked the live reload of Quarkus in quarkus: dev mode, but was disappointed that the running tests were so slow in comparison, and pointed out that script language developers use often continuous testing.
I have to admit my initial reaction was just “this is how it is in Java”, but after sleeping on it I realized that we actually had all the basics we needed in Quarkus to do our own testing. continuous; all we really needed was to write a JUnit tester and wire everything together.
From a developer’s perspective, this gives you almost instant feedback on any changes you make. As soon as you save your code, the tests run and you can see if your changes were effective. We use a very focused approach to running tests, so we only run tests that your change might affect, and the result is a super fast feedback cycle unlike anything I’ve ever experienced with Java. . I’m actually disappointed that I can’t use it when working on Quarkus itself.
From the start, the developer experience has been one of our main goals in Quarkus, taking it to the next level. Since it is integrated into the heart of Quarkus, every user has access to it out of the box. This feature also does not inflate the resulting Quarkus application because no test code ends up in your final application. This means that we can build lightweight cloud-centric applications while still providing a great experience for developers.
InfoQ: This new feature is currently part of the alpha version of Quarkus. When will Quarkus 2.0 be available? Do you plan any changes ahead of GA’s release?
Stuart douglas: At this stage, we are considering mid-June.
At the moment, we’re trying to get as much feedback from the community as possible, and we’ve already made some changes based on the feedback we’ve received. I don’t expect the core functionality to change much between now and release, but the more feedback we get, the better able we will be to troubleshoot issues. There is still work to be done on how we present the results, both in the console and in the development UI, so this will probably be the most visible change to the user between now and release. final.
InfoQ: Are there any known limitations of continuous testing?
Stuart douglas: I guess the biggest limitation is that it has to run all the tests on startup in order to know which tests to run when the code changes. So if you have a huge test suite this can be a problem. There are things we can do to mitigate this, like caching this information between launches, so this will likely improve in future releases.
InfoQ: Are you satisfied with the results so far? Would you like to implement something differently?
Stuart douglas: I think it works better than I expected when I first started experimenting. There will undoubtedly be improvements over time, but I’m really happy with the base architecture.
InfoQ: Can you give us an overview of the details of its implementation? Is there something that you are particularly proud of?
Stuart douglas: The first challenge when the test is enabled is to resolve the test artifacts and create a ClassLoader capable of loading the classes. When you run your application normally, things like JUnit are not present, so we have to fix them manually. This is relatively complex and needs to be done for both Maven and Gradle. But luckily we already had some code that we use to solve the part of the build time of our extensions.
Next, we need to find out about testing, as the development mode has already followed the current workspace to handle changes that simply required adding additional metadata to our existing workspace model. Using this metadata, we can discover the user’s test classes and load them into our new ClassLoader. When we load tests and application classes, we are actually performing bytecode transformations that allow us to track when methods are called. This is how we know which tests affect their corresponding classes.
The next thing we needed was a way to run the tests, which is the only completely new item. It involved writing a JUnit runner, which I had never looked at before, but the API is really really nice, so the implementation is straightforward. When we run the tests at startup, we use the transformation mentioned above to track the tests that use the application classes.
The three items above are all you need to run the tests, but we also need a way to rerun the tests when changing code. The development mode already supports the detection of modified files and their automatic compilation, so we just had to modify it to handle the tests as well. When the source files change, we automatically compile them and look at the class usage data we collected in our first test. From there, we can determine each test that uses the modified classes and run them automatically, without running irrelevant tests.
Of all this, the tester is the only completely new part. Everything else is just an improvement on a feature we already had. What I’m most proud of is how it can exactly trace the tests affected by the code. Without it, you wouldn’t know exactly which tests to run after a change.
InfoQ: Are continuous testing automatically enabled when development mode is enabled?
Stuart Douglas: It is automatically available, but you must press a key to activate it. This can be changed through setup, so you can configure Quarkus to always use continuous testing. Quarkus provides several keyboard shortcuts to control continuous testing, so that you can quickly pause / resume testing, rerun tests, and more.
We also provide a quarkus: test command which will only run tests and not launch development mode. This gives users more flexibility. For example, if you are only doing test-driven development, you might just care about running the tests.
Intended for a GA release in mid-June, Quarkus 2.0 offers, among other features, the ability to continuously run tests while writing code. Similar to the continuous deployment feature added in Quarkus 1.11, continuous testing provides developers with rapid feedback on changed code, promising to quickly spot issues and possibly resolve them. Part of Quarkus’ development mode is out of the box, allowing changes to be made through configuration. Even though it is still in alpha version, only the UI side of the reporting tool will most likely be affected with the basic functionality remaining the same. More details on continuous testing can be found in Douglas’ YouTube video. Developers are encouraged to experiment with this new feature before GA release.