<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Arques on Medium]]></title>
        <description><![CDATA[Stories by David Arques on Medium]]></description>
        <link>https://medium.com/@david.arques?source=rss-87b8e41832e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wMHhD8IpHXiJIVDD</url>
            <title>Stories by David Arques on Medium</title>
            <link>https://medium.com/@david.arques?source=rss-87b8e41832e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 02:48:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@david.arques/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fast Spring Boot API Tests]]></title>
            <link>https://medium.com/clarityai-engineering/fast-spring-boot-api-tests-b2499be1abd9?source=rss-87b8e41832e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2499be1abd9</guid>
            <category><![CDATA[testcontainer]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[api-testing]]></category>
            <dc:creator><![CDATA[David Arques]]></dc:creator>
            <pubDate>Tue, 06 Sep 2022 09:02:38 GMT</pubDate>
            <atom:updated>2022-09-06T09:02:38.577Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we explain the solution we have adopted at <a href="https://twitter.com/ClarityAIEng">Clarity AI</a> to streamline our API Tests using <strong>Spring Boot</strong> and <strong>Testcontainers</strong>.</p><h3>Context</h3><p>At Clarity AI, we like our code to be as well tested as possible, including good coverage. Most of the code base is dedicated to expose REST APIs. In addition to unit and integration tests, we also included tests that run the APIs in an environment as close to the production as possible, including: configuration, security, servlet container, etc. This article is focused on those <strong>API Tests</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*tM0nIOGXXlHDjaiBSWXZ8g.png" /><figcaption>Test Pyramid at Clarity AI</figcaption></figure><p>Our <a href="https://stackshare.io/clarity-ai/clarity-ai-backend">backend tech stack</a> is based on Spring Boot, deploying more than 20 services using MongoDB, PostgreSQL, Redis, Rabbit, etc. So you can imagine that the API Test context creation might be complex and expensive.</p><p>We try to make the execution of our tests as fast as possible, including the aforementioned API Tests. We found a solution to speed them up that we are glad to share with you.</p><p>Spring Boot provides different tools to test your APIs:</p><ul><li><strong>Sliced Test </strong>with @WebMvcTest annotation: Spring Context will only include the required components of the WEB layer.</li><li><strong>Entire</strong> <strong>App Test </strong>with @SpringBootTest annotation: The whole Spring Boot Application Context will be created and accessible. Additionally, an embedded servlet container can be started overriding the static webEnvironment attribute.</li></ul><p>As the number of endpoints to test is very high, we can not afford starting a new app for each of them because it will end up making worse the feedback loop and the developer experience.</p><h3>Solution</h3><p>In order to minimize the impact of the creation of Spring Boot WEB contexts, we have identified two options:</p><ol><li>Make the test context as lightweight as possible. A solution could be defining a custom test context with @TestConfigurationand hand-picking the required beans, or even using mocks.</li><li>Minimize the amount of WEB context creations.</li></ol><p>Taking into account that our applications are stateless, the context of a test can be reused in others. And, since the first alternative does not really meet one of our requirements of replicating the production state, we’ve chosen the second option.</p><p>To learn about the Spring Context creation and caching we found very useful, the article <a href="https://rieckpil.de/improve-build-times-with-context-caching-from-spring-test/">Improve Build Times with Context Caching from Spring Test</a> which we highly recommend.</p><p>Another point to highlight is the use of <strong>Testcontainers</strong>. Each application requires four different containers to be started, and we wanted them to be created just once per execution of the API Test suite. Launching containers only once forces us to use <a href="http://xunitpatterns.com/Shared%20Fixture.html">Shared Fixture pattern</a> which may make tests erratic. This is a tradeoff we consciously chose.</p><p>We’ve created a sample application to illustrate the solution. Here’s the <a href="https://github.com/clarityai-eng/springboot-test">GitHub repo</a>.</p><h4>API Test Configuration</h4><p>We have created an abstract class <a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/testutil/BaseApiTest.java">BaseApiTest</a> that is in charge of configuring the API tests as well as easily reusable among different projects. This class includes:</p><ul><li>The annotation @SpringBootTest setting the parameter webEnvironment to WebEnvironment.RANDOM_PORT so we get a web context with a real servlet container.</li><li>The @Testcontainers annotation to start up the required containers. For the sake of the example, we’ve defined two of them: PosgreSQLContainer and MongoDBContainer.</li><li>In order to inject the configuration for the defined containers, a static method annotated with @DynamicPropertySourceis used.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a678ab2d6f3a421e01282e8a04e05c05/href">https://medium.com/media/a678ab2d6f3a421e01282e8a04e05c05/href</a></iframe><ul><li>An extra test configuration has been added to define the beans needed to create the test setup. This way, the data sources used in the production and tests code are independent. Moreover, It provides us flexibility to use different users, configurations and permissions in the test setup stage. Each bean has been defined in a <em>lazy</em> mode so that they’re instantiated only if they are actually used.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/616249398f0960f93b51b41d045be073/href">https://medium.com/media/616249398f0960f93b51b41d045be073/href</a></iframe><h4>Utility Annotations</h4><p>To simplify the test development, we have created three annotations:</p><ul><li><a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/testutil/TestSetupDataSource.java">@TestSetupDataSource</a>: Convenience annotation to make use of the test Data Source defined in BaseApiTest.</li><li><a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/testutil/TestSetupMongoClient.java">@TestSetupMongoClient</a>: Annotation to make use of the Mongo test client defined in BaseApiTest.</li><li><a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/testutil/ApiBasePath.java">@ApiBasePath</a>: Exposes the base URL of the application, taking into consideration the dynamic port assignment.</li></ul><h4>API Test Suite</h4><p>In this section, we are going to explain the class that extends BaseApiTest, called ApiTest. Which aims at defining the <em>suite</em> of API Tests we want to run in our application.</p><p>Since an application can expose APIs dedicated to different subdomains, including particular setups, a<a href="http://xunitpatterns.com/Testcase%20Class.html"> Testcase Class</a> has been created for each one. Obtaining an elegant and legible API Test <em>suite</em>.</p><p>In order to execute each test file of the different subdomains, we’ve used the <strong>JUnit 5</strong> @Nested, which allows nesting test files within the same class sharing the configuration defined in BaseApiTest.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27af6602325ef32e4c5dbf404a621a9c/href">https://medium.com/media/27af6602325ef32e4c5dbf404a621a9c/href</a></iframe><h4><strong>API Testcase Classes</strong></h4><p>The API Testcase classes(<a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/springboot/CompaniesApiTest.java">CompaniesApiTest</a>, <a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/springboot/EsgApiTest.java">EsgApiTest</a> and <a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/springboot/ControversiesApiTest.java">ControversiesApiTest</a>) are responsible for defining the actual tests to be executed within each API subdomain. They are extended by the ApiTest inner classes because we want them to reuse the same configuration provided by BaseApiTest.</p><p>These classes have been declared as abstract since they are not meant to be executed independently but only within the ApiTest suite.</p><p>Remember that if you want to use a property class, as those annotated with <a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/testutil/TestSetupDataSource.java">@TestSetupDataSource</a> and <a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/testutil/TestSetupMongoClient.java">@TestSetupMongoClient</a>, within the @BeforeAll method, the test lifecycle must be marked as PER_CLASS. You can find an example in <a href="https://github.com/clarityai-eng/springboot-test/blob/d591414094659ab2749800cdecb1d114e65a1c98/src/test/java/ai/clarity/springboot/EsgApiTest.java#L22">EsgApiTest</a>.</p><h3>Conclusions</h3><p>Get your API tests running fast using a complex configuration in Spring Boot is a hard task. This article explained the solution that we’ve implemented at Clarity AI, achieving: faster feedback loop, higher quality tests and better developer experience.</p><p>We are still not totally satisfied with the idea of inheriting from an abstract class and sharing test fixtures. We’d like each test to be independent, but we couldn’t find a way to run them as fast as we’d like, so we keep looking for a better solution. Stay tuned!</p><p>And what about you? How do you implement your API Tests with Spring Boot? Any feedback is more than welcome.</p><p>Thanks to all <a href="https://twitter.com/ClarityAIEng">Clarity AI Engineering Team</a> who have participated in this project and article, especially to co-authors <a href="https://twitter.com/jerolba?lang=en">Jerónimo López</a> and <a href="https://jmiguel.eu/">Jmiguel Rodriguez</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2499be1abd9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clarityai-engineering/fast-spring-boot-api-tests-b2499be1abd9">Fast Spring Boot API Tests</a> was originally published in <a href="https://medium.com/clarityai-engineering">Clarity AI Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clarity CodeArtifact Gradle Plugin]]></title>
            <link>https://medium.com/clarityai-engineering/clarity-codeartifact-gradle-plugin-b3c767bf4c9f?source=rss-87b8e41832e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3c767bf4c9f</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[gradle-plugin]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[codeartifact]]></category>
            <dc:creator><![CDATA[David Arques]]></dc:creator>
            <pubDate>Wed, 26 May 2021 07:08:13 GMT</pubDate>
            <atom:updated>2021-05-26T12:04:34.100Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Grade plugin logo" src="https://cdn-images-1.medium.com/max/574/1*7nN_HHdbN5qUzK0tU7zZGg.png" /></figure><p><a href="https://plugins.gradle.org/plugin/ai.clarity.codeartifact">Clarity CodeArtifact</a> is a Gradle plugin that manages configuration of Maven repositories with CodeArtifact seamlessly, supports several AWS profiles and provides multiple configuration options.</p><h3>Why did we build the plugin?</h3><p>As in many companies, at <a href="https://twitter.com/clarityaieng">Clarity</a> we generate dozens of artifacts for internal use each day, so an artifact manager is mandatory. Some time ago we maintained a <a href="https://www.sonatype.com/products/repository-oss">Nexus</a> repository using <a href="https://aws.amazon.com/ec2">Amazon EC2</a>, but we started to have problems due to internal indexes failures that even ended up stopping all pipelines and developments. So, we considered migrating to other solutions, and finally we chose <a href="https://aws.amazon.com/codeartifact/">CodeArtifact</a>, mainly because almost all our platform is already hosted on Amazon and no maintenance is needed.</p><p>CodeArtifact requires users to authenticate by creating an authorization token using their AWS credentials, which can be a tedious process locally and in the CI environment even more taking into account the usually short token validity period. Most of the Clarity projects use Gradle, so we immediately looked for a plugin that automatically authenticates to CodeArtifact<strong> </strong>and configures the repository user with the needed token<strong> </strong>and believe it or not there were none, so we decided to create a <a href="https://plugins.gradle.org/plugin/ai.clarity.codeartifact">CodeArtifact Gradle Plugin</a> ;)</p><h3>How to use it?</h3><p>Now, let’s see how to use the plugin to automatically authenticate against AWS CodeArtifact using your local credentials. If you haven’t already, first <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html">set up your AWS credentials</a>.</p><p>Just add the following in your <em>build.gradle:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4a224284016e133684bc30ee01bb970/href">https://medium.com/media/c4a224284016e133684bc30ee01bb970/href</a></iframe><h4>Setting the AWS Profile</h4><p>If you need to authenticate to AWS with a different profile than the default, there are four options:</p><p>1.<strong> </strong>Define the environment variable <strong>AWS_PROFILE</strong> with the profile name you want to use.</p><p><strong>Note</strong>: This plugin uses AWS SDK for authorization, all the <a href="https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html">standard environment variables</a> are applicable.</p><p>2. Define the environment variable <strong>CODEARTIFACT_PROFILE</strong> with the profile name you want to use. If you need a different profile for CodeArtifact than for the rest of AWS calls you can use this environment var.</p><p>3. Define the profile using a <strong>system property</strong>. If you need a different profile for CodeArtifact and you cannot define an environment variable, you can define it via system property as well:</p><ul><li>This way using <em>gradle.properties</em> file:</li></ul><pre>systemProp.<strong>codeartifact.profile</strong>=&lt;your profile&gt;</pre><ul><li>Or using the command line:</li></ul><pre>gradle -D<strong>codeartifact.profile</strong>=&lt;your profile&gt; …</pre><p>4. Add the profile name to the repository URL as a<strong> query parameter</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0811404867d17959d06bd665d609cd4c/href">https://medium.com/media/0811404867d17959d06bd665d609cd4c/href</a></iframe><p><strong>Note</strong>: The query parameter is used to configure the profile and automatically removed from the URL in any request to AWS.</p><h3>Collaborations</h3><p>Clarity CodeArtifact Gradle plugin is <a href="https://github.com/clarityai-eng/codeartifact-gradle-plugin">an open-source project</a> under Apache License 2.0. So don’t hesitate to contribute, any feedback or PR are more than welcome.</p><h3>References:</h3><ul><li><a href="https://plugins.gradle.org/plugin/ai.clarity.codeartifact">Clarity CodeArtifact Gradle plugin</a></li><li><a href="https://github.com/clarityai-eng/codeartifact-gradle-plugin">GitHub repository</a></li><li><a href="https://docs.aws.amazon.com/codeartifact/latest/ug/tokens-authentication.html">AWS CodeArtifact authentication and tokens</a></li><li><a href="https://docs.aws.amazon.com/codeartifact/latest/ug/maven-gradle.html">Use CodeArtifact with Gradle</a></li><li><a href="https://docs.gradle.org/current/userguide/custom_plugins.html">Developing Custom Gradle Plugins</a></li></ul><p>Thanks to all <a href="https://medium.com/u/1f4bc256d0ef">Clarity AI Engineering Team</a> who have participated in this project and article, especially to <a href="https://github.com/jfisbein/">Joan Fisbein</a>, <a href="https://medium.com/u/8812bc8f63c9">Jerónimo López</a> and <a href="https://jmiguel.eu/">Jmiguel Rodriguez</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3c767bf4c9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clarityai-engineering/clarity-codeartifact-gradle-plugin-b3c767bf4c9f">Clarity CodeArtifact Gradle Plugin</a> was originally published in <a href="https://medium.com/clarityai-engineering">Clarity AI Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>