<?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 Tyson Gern on Medium]]></title>
        <description><![CDATA[Stories by Tyson Gern on Medium]]></description>
        <link>https://medium.com/@tygern?source=rss-f02b138e12e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nzkY3l-DA2Fnq-B2viZ4iA.jpeg</url>
            <title>Stories by Tyson Gern on Medium</title>
            <link>https://medium.com/@tygern?source=rss-f02b138e12e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 14:16:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tygern/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[The Unit in Unit Testing]]></title>
            <link>https://content.initialcapacity.io/the-unit-in-unit-testing-da637d85a363?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/da637d85a363</guid>
            <category><![CDATA[test-doubles]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[extreme-programming]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 15:14:15 GMT</pubDate>
            <atom:updated>2023-03-22T15:14:15.935Z</atom:updated>
            <content:encoded><![CDATA[<h4>Increase test maintainability and build confidence</h4><p><em>This article was </em><a href="https://www.infoq.com/articles/unit-testing-approach"><em>originally published on InfoQ</em></a><em> on February 21, 2023.</em></p><h4>Key Takeaways</h4><ul><li>Unit tests should increase confidence that our code works correctly, allow us to document how our code should function, and aid in designing loosely coupled, highly cohesive software.</li><li>Unit tests are isolated from the rest of the codebase, which helps them to be fast to run, simple to write, and easy to understand and maintain.</li><li>Test doubles, or objects that take the place of collaborators, can help to facilitate the isolation of unit tests.</li><li>The heavy use of mock objects in unit tests provides a lesser degree of confidence that the behavior under test functions correctly.</li><li>A fake object can keep a unit test isolated while increasing confidence that it tests the desired behavior.</li></ul><p>Developers write tests to increase confidence that production code works correctly, to document intentions, and to aid in application design. Lately, we’ve seen developers trend toward heavy use of test doubles, especially mocks, in unit tests. This is done to improve the speed of tests, decrease test dependencies on infrastructure, or reduce the number of objects that a test depends on. However, it often comes at an unacceptably high cost of lower confidence, unclear documentation, and high coupling between implementation and test code.</p><p>To avoid these drawbacks, developers should consider using fake objects instead of mock objects, as fake objects offer similar isolation benefits while driving high confidence, clear documentation, and loose coupling between implementation and test code.</p><h3>Background</h3><p>We label lower-level tests unit tests to describe that these tests are somehow isolated from the code around them. Because of this isolation, unit tests should be fast to run, simple to write, and easy to understand and maintain.</p><p>Developers often use test doubles as a way to facilitate this isolation. A test double is any object used in a test that takes the place of a collaborator. In his book <a href="http://xunitpatterns.com/">xUnit Test Patterns</a>, Gerard Meszaros defines several categories of test doubles: dummies, spies, stubs, fakes, and mocks. For our purposes, we’ll focus on the last two:</p><ul><li><a href="http://xunitpatterns.com/Mock%20Object.html">Mock objects</a> are preprogrammed with specifications of the calls they expect to receive and their response to these calls. They have a mechanism to verify that they receive the correct calls during a test and will fail the tests if the calls don’t match their expectation. People often use frameworks like Mockito, Mockk, or GoMock to create mock objects.</li><li><a href="http://xunitpatterns.com/Fake%20Object.html">Fake objects</a> are functioning implementations of collaborators that take some kind of shortcut to make them more suitable to run in a test environment. For example, a developer might create an in-memory datastore to take the place of an object that saves data to S3 to run the tests locally.</li></ul><p>It’s common for virtually everything to be mocked in the test suite of a modern codebase and for the suite to run without any supporting services. In such a case, the test suite provides a high degree of confidence that each piece of the system works correctly in isolation but little confidence that they work correctly together. Later, we’ll discuss when mocks are inappropriate to use.</p><p>For example, many test suites mock the database layer during testing. Tests check that the right calls are made to the database and use pre-programmed responses. It’s hard for such a test suite to give us confidence that the code will behave correctly in production since the database is never exercised, and the expected calls programmed into the mocks might not be correct, not to mention that with a mock-only approach, SQL statements go untested.</p><h3>Isolation</h3><p>There’s general agreement that the word unit in unit testing refers to units of isolation,. That is, unit tests are isolated, at some level, from the rest of the codebase. However, opinions differ when defining what the unit is that is being isolated.</p><p>This definition is essential. The unit of isolation shapes the scope of each test, the relationship between test code and production code, and ultimately the application architecture. Historically, there have been widely accepted definitions of a unit, which we will discuss below.</p><h4>Test isolation</h4><p><a href="https://twitter.com/KentBeck">Kent Beck</a>, representing the classical approach to testing, argues that</p><blockquote>Unit tests are completely isolated from each other, creating their test fixtures from scratch each time.</blockquote><p>In this approach, the word unit in unit testing refers to the test itself: unit tests are isolated from other tests. Beck argues that “tests should be coupled to the behavior of code and decoupled from the structure of code.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3lvp9JG9jI_iAMaUX40Sew.png" /><figcaption>Test isolation</figcaption></figure><p>Tests written using this approach tend to have few mocks. They instead use instances of collaborating objects and even real supporting infrastructure (such as databases) to support each test run.</p><p>For example, a classical test whose subject makes database calls would use the actual database during tests. The tests would ensure the database is in the right state before running and assert that the resulting database state matches expectations.</p><p>A classical test with a subject that makes external HTTP calls would make HTTP calls when running the test. Since external calls often decrease test reliability, the author might start an HTTP server locally that behaves similarly to the external service.</p><p>Classical-style tests provide a high degree of confidence that the tested code behaves correctly. When the code is refactored, the tests tend not to change since they know little about the external interface of collaborators.</p><h4>Subject isolation</h4><p>Steve Freeman and Nat Pryce, representing the mockist approach to testing, argue that</p><blockquote>[unit tests] exercise objects, or small clusters of objects, in isolation.</blockquote><p>Freeman argues that unit tests are “important to help us design classes and give us confidence that they work, but they don’t say anything about whether they work together with the rest of the system.” In this approach, the word unit in unit testing refers to the subject being tested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHFI5o3UKJ6A9v9gM9SQpQ.png" /><figcaption>Subject isolation</figcaption></figure><p>Tests written using this approach must use test doubles to stand in for collaborators and tend to have many mocks. They rarely use real supporting infrastructure, favoring mocks or fakes. The idea is that we should isolate test subjects from the behavior of their collaborators during tests; a change in the behavior of one object should not impact the tests of another object. Developers also use mocks to increase the speed and reliability of their tests, using mocks to take the place of slow or unreliable collaborators.</p><p>For example, a mockist test whose subject makes database calls would mock the database layer when running the test. The subject would interact with the mock database object, recording calls as it returned canned responses during a test, and checking expectations at the end.</p><p>A mockist test with a subject that makes external HTTP calls would use a mock HTTP client when running the test. This client would return pre-programmed responses to HTTP calls during the test. After the test, the test author would use the mock to check that the right HTTP calls had been made.</p><p>These tests tend to run quickly and reliably, but they provide a lesser degree of confidence that the behavior under test functions correctly. When the code is changed or refactored, the tests tend to require significant changes since they have an intimate knowledge of the external interface of collaborators.</p><p>Additionally, using mocks increases the amount of test code. In many languages, like Go, mockist must write or generate all mocks and keep the code in their codebase. This effectively doubles the size of the test suite. Even in languages like Kotlin and Java, where mocks are generated at runtime, the mocks must be programmed before each test and verified after each test, which results in more test code to maintain.</p><h3>In practice</h3><p>To determine the approach to use in practice, we must first enumerate the goals we are trying to achieve by writing tests. We want to:</p><ul><li>Increase confidence that our code works correctly.</li><li>Document how our code should function.</li><li>Aid in designing loosely coupled, highly cohesive software.</li></ul><p>With these goals in mind, I’d argue to start with the test isolation approach to unit tests. If each test runs reliably in isolation while using as many real collaborators as possible, we achieve the following.</p><p>Confidence, since our tests run in a production-like environment. We can be confident that our test subjects function correctly in isolation and in concert. Our tests also give us confidence that our subjects behave correctly in concert with their external collaborators. When using a mockist approach, we don’t have the same confidence that our test subjects work well together.</p><p>Clear documentation, since readers can see how our code should be used in the production-like environment. Developers who read our tests can simply, for example, examine the expected database state meant to result from a given operation to see what will happen in production. Developers who read mockist tests must translate each mock’s responses and expectations into the operations on the actual collaborator, which significantly reduces clarity and readability.</p><p>Thoughtful design. Refactorings happen independent of test code, so they are relatively easy to perform and thus happen frequently. If using a mockist approach, refactoring an object by changing its external interface, for example, requires re-writing or re-generating all the mocks for this object as well. There are no mocks to rewrite when using the classical approach, so refactoring requires fewer changes in test code. This makes refactorings easier to perform, which means it happens more often, and the design of the codebase improves over time.</p><h4>Be flexible</h4><p>In practice, I advise a test isolation approach that starts with the classical style and falls back on the mockist style when necessary. Martin Fowler says, “I don’t treat using doubles for external resources as an absolute rule. If talking to the resource is stable and fast enough for you, then there’s no reason not to do it in your unit tests. […] Indeed when xunit testing began in the ’90s, we made no attempt to go solitary unless communicating with the collaborators was awkward (such as a remote credit card verification system).”</p><p>As long as we’re using fast, reliable collaborators (which should be our goal anyway), testing with real collaborators doesn’t negatively impact the speed and reliability of our tests. When this is not the case (when collaborating with an external service over HTTP, for example), test doubles are a great way to increase a test’s speed and reliability while sacrificing a bit of confidence, clarity, and flexibility.</p><p>When considering the type of test double to use, favor fakes over mocks. Fakes have a few key advantages over mocks:</p><ul><li>A fake behaves more similarly to the real collaborator than a mock, giving us more confidence.</li><li>We interact with a fake in the same way that we interact with a real collaborator, so it provides better documentation.</li><li>A fake must be updated whenever the real collaborator is updated, just like a mock. However, with fakes, no expectations or verifications need to be updated, so refactoring a codebase with fakes tends to be easier than refactoring a codebase with mocks.</li></ul><h3>Conclusion</h3><p>When determining your testing approach, think carefully about your approach to unit isolation, so you’re aware of the benefits and tradeoffs of starting with a classical or a mockist approach. Always be willing to adapt your approach depending on the nature of your collaborators. Ultimately we all want a fast, reliable test suite that gives us the confidence to ship, documents our intentions clearly, and helps us to design an extensible system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da637d85a363" width="1" height="1" alt=""><hr><p><a href="https://content.initialcapacity.io/the-unit-in-unit-testing-da637d85a363">The Unit in Unit Testing</a> was originally published in <a href="https://content.initialcapacity.io/">initialcapacity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Initial Engagement]]></title>
            <link>https://content.initialcapacity.io/initial-engagement-1da557e1cae3?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1da557e1cae3</guid>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 15:30:42 GMT</pubDate>
            <atom:updated>2022-11-10T17:18:33.744Z</atom:updated>
            <content:encoded><![CDATA[<p>As our tagline suggests, Initial Capacity improves the way software is written while also improving the lives of those who create it. We have a unique flow for new customers that helps us to achieve this impact while providing maximum business value. Our goal is for our prospective customers to learn more about shipping software regardless of whether we ultimately decide to work together.</p><h3>Initial customer checklist</h3><p>Initial Capacity’s sweet spot is working with customers who have a bit of funding, have validated their product-market fit, and are ready to turn their software development process <a href="https://www.youtube.com/watch?v=4xgx4k83zzc">up to 11</a>. We help our customers get to production quickly then quickly iterate and add features. Software is never done, and our goal is to enable our customers to take their vision forward rather than relying on us for too long. If you check a few of the boxes below then you’re likely in a great position engage with us.</p><ul><li>We have an immediate need for a new feature set or product</li><li>We know what we would like to build</li><li>We are unable to hire fast enough</li><li>We may not need as many people long-term to support the product</li><li>We would like to start with best practices instead of learning along the way</li><li>We would like to build high-quality software with high test coverage</li><li>We would like to hit the ground running with an existing team</li></ul><p>Contact us at <a href="/service/mailto:info@initialcapacity.io">info@initialcapacity.io</a> to get started!</p><h3>Scoping</h3><p>Scoping is one of the first meetings that we have with customers, and helps to define our engagement. The purpose of the scoping is to estimate a project’s costs, to agree on a timeline, and to start to learn about the product.</p><p>During a 2–4 hour scoping meeting we facilitate a few exercises designed to help both of us understand the project better. These exercises help us to tease out the goals, risks, integrations, and high-level users and features involved. It’s important that your key stakeholders attend the meeting, and we’ll be sure to bring a balanced team of experts.</p><p>After the scoping we send you a proposal containing our proposed solution with an estimated timeline and cost. Over the years we’ve gotten to be pretty good with our estimates due to the wide variety of customers and industries that we’ve worked with. Our estimates are based on past projects, and chances are we’ve done something similar before.</p><h3>Inception</h3><figure><img alt="A table full of user stories" src="https://cdn-images-1.medium.com/max/1024/1*UkvISOrsoBR6X8mojh6CYA.jpeg" /></figure><p>The inception meeting is the formal kickoff to our engagement. We meet for 1–2 days to dive deeper into goals, risks, integrations, and high-level features. Much of the time is spent breaking down the high-level features into actionable user stories for the backlog with the goal of starting development work the next day.</p><p>As with the scoping, it’s vital that the customer’s stakeholders attend to ensure the backlog aligns with their priorities. In addition, the members of the project team (developers, product, design, security, etc.) from the customer and Initial Capacity should attend to quickly gain context.</p><h3>Engagement</h3><p>During the engagement you’re in the driver’s seat. We push to a production-like environment multiple times per day, where you’re able to test the app and see our changes within minutes. We work out of a prioritized backlog to make sure we’re always working on your top priority. You have full control over the backlog, so the software team reacts quickly when your priorities change.</p><p>We meet at the beginning of each week to review the backlog and make sure that the team understands the work to be done. At the end of the week we hold a retrospective meeting to review the week’s work and adjust the team’s process as necessary.</p><h3>Post-engagement</h3><p>During an engagement we work side-by-side with you and your team. By the end of the engagement you’re as much of an expert about the product as we are.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1da557e1cae3" width="1" height="1" alt=""><hr><p><a href="https://content.initialcapacity.io/initial-engagement-1da557e1cae3">Initial Engagement</a> was originally published in <a href="https://content.initialcapacity.io/">initialcapacity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring dependency management]]></title>
            <link>https://medium.com/tips-from-the-cloudnative-playground/spring-dependency-management-539e02c306bd?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/539e02c306bd</guid>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring-cloud]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Tue, 08 Aug 2017 16:42:17 GMT</pubDate>
            <atom:updated>2017-08-08T16:42:17.521Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing dependency versions in a distributed system is a problem with many variables. While there’s no silver bullet that solves it easily, there are ways to approach dependency management that can simplify the problem. I use the following process to ensure version compatibility between dependencies when building a distributed system with Spring Boot and Spring Cloud.</p><p>While these strategies will work with a wide variety of architectures and codebase structures, this article will follow the architecture described in <a href="http://www.appcontinuum.io/">The Application Continuum</a>. Additionally, I include a <em>platform-services</em> folder that contains Spring Cloud Services applications. These applications may be used for local development or can be deployed to cloud environments.</p><h3>Software to consider</h3><p>A typical application using Spring Cloud will have dependencies on the following libraries:</p><ul><li>Spring</li><li>Spring Boot</li><li>Jackson, SLF4J</li><li>Spring Cloud</li><li>Netflix OSS (Eureka, Hystrix, etc.)</li><li>Spring Cloud Services</li></ul><p>It is vital to use compatible versions of these dependencies. Failing to do so may cause runtime errors that are hard to debug.</p><p>There are two different packages that contain Spring Cloud Dependencies: org.springframework.cloud and io.pivotal.spring.cloud. The io.pivotal.spring.cloud dependencies will allow your applications to easily bind to services on <a href="https://pivotal.io/platform">Pivotal Cloud Foundry</a>, so it is best to use them when deploying to PCF.</p><h3>Where to put dependencies</h3><p>Use these guidelines when deciding where to store dependencies:</p><ul><li>The <em>applications </em>folder contains dependencies on Spring Boot and Spring Cloud.</li><li>The <em>components</em> folder contains dependencies on Spring, Jackson, SLF4J, and Netflix OSS.</li><li>The <em>platform-services</em> folder contains dependencies on Spring Cloud Services.</li></ul><h3>How to keep track of versions</h3><p>Store variables containing common dependency versions in the top-level build.gradle file in a buildscript.ext closure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb6496f131cd20751f0aa58f30635b3f/href">https://medium.com/media/bb6496f131cd20751f0aa58f30635b3f/href</a></iframe><p>These variables can then be used in the subprojects’ build.gradle files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8be93688d15e488040f782a31260fa7a/href">https://medium.com/media/8be93688d15e488040f782a31260fa7a/href</a></iframe><p>Spring Boot and Spring Cloud use the Gradle <a href="https://github.com/spring-gradle-plugins/dependency-management-plugin">Dependency Management Plugin</a> to manage dependency versions. The plugin uses Maven boms to synchronize dependency versions. It is vital to make sure that your bom versions are compatible with each other. If two versions that come from different boms conflict, you may run into unexpected behavior since dependencies resolve in unexpected ways.</p><p>If you are using Spring Boot 1.x, be aware that the Spring Boot Gradle plugin will automatically apply the dependency management plugin with your version of the spring-boot-dependencies bom. Thankfully, this will <a href="https://spring.io/blog/2017/04/05/spring-boot-s-new-gradle-plugin#dependency-management">not be the case</a> for Spring Boot 2.x.</p><p>When I use the dependency management plugin I limit its use to the applications and platform-services folders, since these are the only places with containing Spring Boot or Spring Cloud dependencies.</p><h3>How to find versions</h3><p>I use several sources to find compatible versions:</p><ul><li><a href="https://mvnrepository.com/">MVNrepository</a> is my go-to search engine for Maven Central.</li><li>Run gradle dependencies to see a list of all project dependencies and versions.</li><li>The IntelliJ <a href="https://www.jetbrains.com/help/idea/gradle-tool-window.html">Gradle tool window</a> has collapsable view of your current Gradle dependencies.</li><li>This Spring Cloud Services <a href="https://docs.pivotal.io/spring-cloud-services/common/client-dependencies.html">client dependency chart</a> shows compatible versions of Spring Cloud Services, Spring Boot, and Spring Cloud.</li></ul><h3>How to choose versions</h3><p>Start by determining the version of Spring Cloud Services that is available on your Cloud Foundry installation. If you are manually deploying Spring Cloud Services, choose the latest approved version.</p><p>Next, choose the highest approved version of Spring Boot that is compatible with your Spring Cloud Services version, and finally pick the compatible Spring Cloud version. Once these versions are set, versions for Spring, Netflix OSS, Jackson, SLF4J, and others can be found using the MVNrepository search or by searching through Gradle dependencies.</p><p>Once you’ve found your version numbers add them to the buildscript.ext closure. As your project accumulates more dependencies use these same methods to ensure compatibility. When you upgrade versions be sure to check compatibility between your new versions.</p><h3>Wrap-up</h3><p>This method is a reasonable starting point for managing Spring dependencies, but it will require adjustment over the course of a project. Some projects have client-specific libraries that require another layer of management techniques, while other projects with straightforward dependency structures can use a simpler technique. Above all, be ready to change your strategy when you experience friction, and be as consistent as possible across similar projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=539e02c306bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tips-from-the-cloudnative-playground/spring-dependency-management-539e02c306bd">Spring dependency management</a> was originally published in <a href="https://medium.com/tips-from-the-cloudnative-playground">Tips from the Cloudnative Playground</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring a Java application for local development]]></title>
            <link>https://medium.com/tips-from-the-cloudnative-playground/configuring-a-java-application-for-local-development-60e2c9794ca7?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/60e2c9794ca7</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Fri, 05 May 2017 16:27:51 GMT</pubDate>
            <atom:updated>2017-05-05T16:27:51.154Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://12factor.net/config">third factor</a> of the T<em>welve-Factor App</em> methodology promotes storing configuration in the environment rather than in code. To ensure that our code runs correctly we must be able to run the same build artifact in each environment, which should provide our application with the information necessary for it to run.</p><h3>The problem</h3><p>Many Java applications store development-specific configuration in an <em>application.properties</em> or <em>application.yml</em> file. These files are included in the application’s jar file, violating the third factor. Such a configuration file might look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee8a4d464d1f226f814b32257a4369d6/href">https://medium.com/media/ee8a4d464d1f226f814b32257a4369d6/href</a></iframe><p>These configuration properties are often overridden with environment variables in other environments. In some cases, developers even check environment-specific profiles into source control, flagrantly violating the third factor.</p><h3>A cumbersome solution</h3><p>A common way to externalize configuration is to store all development configuration in environment variables. This successfully conforms to 12-factor, but can be inconvenient to manage. Consider the following command, which we would use to start our application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de06045bdf58d6fe99f9c14dcd3a77ca/href">https://medium.com/media/de06045bdf58d6fe99f9c14dcd3a77ca/href</a></iframe><p>This solution becomes messier as the number of properties grows. Setting up a new development environment is cumbersome. Running the application from an IDE can be a pain. The addition of a new property must be manually communicated to the whole team.</p><p>If a different configuration is needed for testing, developers must remember to set the right properties before running tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0df49b24dd1fc5092d89f907db11f706/href">https://medium.com/media/0df49b24dd1fc5092d89f907db11f706/href</a></iframe><h3>An better solution</h3><p>The <a href="https://docs.gradle.org/current/userguide/java_plugin.html">Gradle Java Plugin</a> provides us with a way to set environment variables in our buildscript without including them in our build artifacts.</p><p>Any task extending the <a href="https://docs.gradle.org/3.4.1/dsl/org.gradle.api.tasks.JavaExec.html">JavaExec</a> task (like the <a href="https://github.com/spring-projects/spring-boot/blob/4a3d389bc33b5ea1095607f5e8a21d59281189fc/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java">BootRun</a> task from the Spring Boot plugin) or the <a href="https://docs.gradle.org/3.4.1/javadoc/org/gradle/api/tasks/testing/Test.html">Test</a> task has an <em>environment</em> method which sets task-specific environment variables. This lets us easily set properties for any of our development tasks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2925846265543383e6937907dcee4cae/href">https://medium.com/media/2925846265543383e6937907dcee4cae/href</a></iframe><h3>Sensitive properties</h3><p>If we need to configure sensitive properties there are a couple of options. We can use environment variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c616d4d744ac284701c7092048132c33/href">https://medium.com/media/c616d4d744ac284701c7092048132c33/href</a></iframe><p>As discussed above, this approach can become unwieldy as the number of secrets grows. We can also use a local <em>properties</em> file (which is not included in our jar, of course).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3dbe4d64b0a7cbfa58fbd3eecca7126/href">https://medium.com/media/a3dbe4d64b0a7cbfa58fbd3eecca7126/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9886bb4ef8a717d95671d41ec43fffc6/href">https://medium.com/media/9886bb4ef8a717d95671d41ec43fffc6/href</a></iframe><p>However, we run the risk of accidentally checking out secrets into source control.</p><p>Following either of these methods will help you build a 12-factor application that allows for flexible deploys to multiple environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60e2c9794ca7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tips-from-the-cloudnative-playground/configuring-a-java-application-for-local-development-60e2c9794ca7">Configuring a Java application for local development</a> was originally published in <a href="https://medium.com/tips-from-the-cloudnative-playground">Tips from the Cloudnative Playground</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring OAuth authentication on PCF]]></title>
            <link>https://medium.com/tips-from-the-cloudnative-playground/spring-oauth-authentication-on-pcf-e5f1ac330309?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5f1ac330309</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[oauth2]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Fri, 18 Nov 2016 19:42:25 GMT</pubDate>
            <atom:updated>2016-11-18T19:42:25.447Z</atom:updated>
            <content:encoded><![CDATA[<p>We can use <a href="https://projects.spring.io/spring-boot/">Spring Boot</a> and <a href="https://projects.spring.io/spring-security/">Spring Security</a> to create a web application that authenticates users against an OAuth2 provider. Just add <em>spring-boot-starter-web</em> and <em>spring-cloud-starter-oauth2</em> to your <em>build.gradle</em> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ca1826826290ed2ca35478334df91bd/href">https://medium.com/media/5ca1826826290ed2ca35478334df91bd/href</a></iframe><p>Then add a configuration file to enable security for the application. In this example we’ll secure all endpoints.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1dff6be0d498f39c280284498f8492c/href">https://medium.com/media/a1dff6be0d498f39c280284498f8492c/href</a></iframe><p>We now have to configure our application with the endpoints, client id, and client secret needed to communicate with out OAuth2 provider.</p><p><a href="https://pivotal.io/platform">Pivotal Cloud Foundry</a> (PCF) provides a <a href="https://docs.pivotal.io/pivotalcf/concepts/architecture/uaa.html">User Account and Authentication</a> (UAA) server that acts as an OAuth2 provider interfacing with many different backends. On our PCF instance we can create a <a href="https://docs.pivotal.io/p-identity/">Single Sign-On</a> service which creates a UAA instance. We bind this service to out application which makes the necessary endpoints and credentials for communication.</p><p>To allow our application to use this configuration we’ll add <em>spring-cloud-sso-connector</em> to our dependencies .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c654e69a2db5f28bdc721aa803db8bae/href">https://medium.com/media/c654e69a2db5f28bdc721aa803db8bae/href</a></iframe><p>When we deploy to PCF we can bind the SSO service to our application and it will be able to successfully authenticate users against our backend of choice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5f1ac330309" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tips-from-the-cloudnative-playground/spring-oauth-authentication-on-pcf-e5f1ac330309">Spring OAuth authentication on PCF</a> was originally published in <a href="https://medium.com/tips-from-the-cloudnative-playground">Tips from the Cloudnative Playground</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Local service discovery with Ribbon]]></title>
            <link>https://medium.com/tips-from-the-cloudnative-playground/local-service-discovery-with-ribbon-60bdffb198e4?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/60bdffb198e4</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[cloud-foundry]]></category>
            <category><![CDATA[eureka]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Fri, 18 Nov 2016 18:35:05 GMT</pubDate>
            <atom:updated>2016-11-18T18:35:05.283Z</atom:updated>
            <content:encoded><![CDATA[<p>Using the service discovery pattern is a common way to manage interactions between applications and services in a distributed system. <a href="http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html">Spring Cloud Netflix</a> includes Eureka and Ribbon to help implement this pattern. Users run a Eureka server that acts as a service registry, client applications self-register with the Eureka server, and Ribbon coordinates client-side load balancing.</p><p>In production environments <a href="https://pivotal.io/platform">Pivotal Cloud Foundry</a> allows developers to easily run a Eureka server and to automatically configure client applications to self-register with that server. During local development this process is a bit more manual. Developers must ensure that a Eureka server is always running and must configure each client to register with the server. This can be especially clunky when running integration tests, as the test suite must manage the startup and shutdown of the Eureka server.</p><p>Fortunately, we can configure Ribbon to bypass the Eureka server and allow services to communicate with each using local configuration. Consider the following example. Suppose we have three applications running locally: <strong>todo-app</strong> on port <em>8080</em>, <strong>task-service</strong> on port <em>8081</em>, <strong>notification-service</strong> running on port <em>8082</em>. We provide our application with the following configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0220cb44554613ffeb9a5ff0f21f119/href">https://medium.com/media/d0220cb44554613ffeb9a5ff0f21f119/href</a></iframe><p>This configuration accomplishes the following.</p><ul><li>Instruct clients not to attempt to register with the Eureka server.</li><li>Configure Ribbon to resolve service addresses without Eureka.</li><li>Provide the location of each service to Ribbon.</li></ul><p>We are able to run tests and run our system in our local environment without the needing to run a local Eureka server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60bdffb198e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tips-from-the-cloudnative-playground/local-service-discovery-with-ribbon-60bdffb198e4">Local service discovery with Ribbon</a> was originally published in <a href="https://medium.com/tips-from-the-cloudnative-playground">Tips from the Cloudnative Playground</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Responses in Ruby]]></title>
            <link>https://medium.com/@tygern/service-responses-in-ruby-e9fb716eed12?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9fb716eed12</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Thu, 27 Aug 2015 16:24:08 GMT</pubDate>
            <atom:updated>2015-08-27T16:24:08.666Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating service objects is a popular way to keep your models small in a Ruby codebase. It helps classes follow the Single Responsibility Principle and allows the code to express its intent much more clearly. Furthermore, extracting services highlights dependencies between objects, resulting in a clearer path for component extraction.</p><p>When a project grows to include many service objects, it becomes challenging to manage the different ways each service is used. It is particularly difficult to know what to expect as a return value and what a specific return value expresses. Consider the following example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/676cc749915015d97ed5ca2a820747f2/href">https://medium.com/media/676cc749915015d97ed5ca2a820747f2/href</a></iframe><p>As a consumer of the <em>UserRepository,</em> we must know that the repository returns a user object. In addition, we need to understand that the repository succeeds when a user is returned and when <em>user.persisted?</em> returns true. As a consumer of the <em>UserNotifier</em> the <em>UserCreator</em> must know that it returns true or false to indicate its success. Any consumer of our <em>UserCreator</em> must know that it returns a user object, and that it succeeds when <em>user.errors</em> is blank.</p><p>Needing to know all of this information simply to use these services becomes very cumbersome. This makes it difficult to ramp up new developers since they must dig into each service to learn how to consume it.</p><p>I prefer to have each service return a simple <em>ServiceResponse</em> object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/246bf6f7e6e567e596216f9c276b6b06/href">https://medium.com/media/246bf6f7e6e567e596216f9c276b6b06/href</a></iframe><p>When we expect a service to return a <em>ServiceResponse</em> we can easily tell when the service succeeds, what the errors are, and which entity it affected. Let’s take a look at how the <em>UserCreator</em> changes when each service it consumes returns a S<em>erviceResponse</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57ff5915c9c363706807c6e09546040c/href">https://medium.com/media/57ff5915c9c363706807c6e09546040c/href</a></iframe><p>The <em>UserCreator</em> looks a bit cleaner and knows less about the objects it consumes. It doesn’t know that <em>user</em> responds to <em>persisted?</em> or <em>errors</em>. Any consumer of the <em>UserCreator</em> knows when it succeeds, what it modifies, and how to retrieve errors. This allows a new addition to the development team to use the <em>UserCreator</em> without having to dig into the class. When service responses are used throughout a large codebase the services become more loosely-coupled and more manageable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9fb716eed12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated User Creation]]></title>
            <link>https://medium.com/@tygern/automated-user-creation-189223256c07?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/189223256c07</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Wed, 26 Aug 2015 10:58:48 GMT</pubDate>
            <atom:updated>2015-08-26T13:22:29.813Z</atom:updated>
            <content:encoded><![CDATA[<p>When developing a web application it is crucial to be able to efficiently click-test. Even with a comprehensive test suite, click-testing edge cases is a useful tool when driving out a feature. However, click-testing can often be time consuming, especially when a complex set of objects must be created to test the desired feature. To help speed thing up, I like to create scripts in javascript to automate as much of this process as possible.</p><p>User signup is often a bottleneck in click-testing. This step often requires inputting a large amount information, some of which cannot conflict with other users’ information. In these situations I like to use timestamps to ensure uniqueness, and the browser’s local storage to keep track of created users.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e01ff6154431fcabba2d7ef4a847e263/href">https://medium.com/media/e01ff6154431fcabba2d7ef4a847e263/href</a></iframe><p>We see that the inclusion of the timestamp in the username and email ensure that our created user is unique, and that our user is persisted in a users string in local storage. Now if we want to log in as our created user we can use the following script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e67b87160f4fbf5d3dbe5fee6802386d/href">https://medium.com/media/e67b87160f4fbf5d3dbe5fee6802386d/href</a></iframe><p>To see a list of users that we’ve created we can run,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6181d10e928286360f383043aa8e60a3/href">https://medium.com/media/6181d10e928286360f383043aa8e60a3/href</a></iframe><p>and to delete all create users we can run,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a61b7ddb277abfb4622b1ffa28ec8833/href">https://medium.com/media/a61b7ddb277abfb4622b1ffa28ec8833/href</a></iframe><p>Each of these scrips can be added to Chrome as a bookmark by collapsing the script to one line and appending with javascript:. This way we can create a Chrome profile for our application and share scripts between developers. We can make these scripts even easier to call by creating a search engine (Chrome allows search engines to be called by shortcuts in the location bar). Simply paste the same url from the bookmark into the search engine url, and type a shortcut into the keyword field. Then we can run our scripts without taking our hands off the keyboard.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=189223256c07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Non Sequential ID Generation]]></title>
            <link>https://medium.com/@tygern/non-sequential-id-generation-6bd716ca033f?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bd716ca033f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Wed, 26 Aug 2015 10:54:10 GMT</pubDate>
            <atom:updated>2015-08-26T13:18:57.901Z</atom:updated>
            <content:encoded><![CDATA[<p>Many web applications expose database ids of domain objects in their urls as a way to easily access these objects. Most web frameworks default to using sequential ids, which can result in exposing sensitive business data, such as total number of users.</p><p>Using UUIDs is one way to solve this problem, but it is often convenient for ids to be short and easily pronounceable. We can use the following method to produce 9 digit non-sequential numbers which have the advantage of being pronounceable. Let’s start by creating a sequence.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73bd376d3f937ce3baa5e13622851dbc/href">https://medium.com/media/73bd376d3f937ce3baa5e13622851dbc/href</a></iframe><p>We’ll use the fact that if <em>p</em> is a prime number, then <em>a % p</em> is equal to <em>b % p</em> if and only if <em>a</em> and <em>b</em> are equal. A quick search tells us that 999999937 is the largest 9 digit prime, and we can pick another pair of large numbers, say9369712273 and 1365089121 to generate a series of non-sequential numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7437fd79c753f8bd545c18971994c0c/href">https://medium.com/media/a7437fd79c753f8bd545c18971994c0c/href</a></iframe><p>Note that the numbers generated but this function are not truly random, so this might not be the best way to generate ids for extremely sensitive information. Now we can create our users table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb74e33760c33ec665823dcdc6095674/href">https://medium.com/media/eb74e33760c33ec665823dcdc6095674/href</a></iframe><p>If we insert a few users into our table, we see that we end up with a nice series of non-sequential ids.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f475972c341e656ee09f00df8040bd3c/href">https://medium.com/media/f475972c341e656ee09f00df8040bd3c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bd716ca033f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing External Services]]></title>
            <link>https://medium.com/@tygern/testing-external-services-2cabed948807?source=rss-f02b138e12e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cabed948807</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Tyson Gern]]></dc:creator>
            <pubDate>Wed, 26 Aug 2015 10:52:39 GMT</pubDate>
            <atom:updated>2015-08-26T13:15:34.253Z</atom:updated>
            <content:encoded><![CDATA[<p>When working on web projects it is often necessary to integrate with an external service, such as Stripe or Twitter. It is important to be able to integration test these services so that we can be confident that our integrations are working. While many web services provide testing environments, it is easy to clutter our integrations when we are running test, development, acceptance, staging, and production environments.</p><p>I’ve developed a pattern that I like to use in a Capybara test suite to handle testing external services and facilitating the cleanup. Suppose we are integrating with a (ficticious) service called Zippy, which manages our users’ accounts, using a Zippy gem. I’d start by putting the following class in <em>spec/support</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2abd5144e74d5724e42fac516e11b4b/href">https://medium.com/media/f2abd5144e74d5724e42fac516e11b4b/href</a></iframe><p>Then I can use the <em>ZippyEnvironment</em> in my Capybara tests to ensure cleanup.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33a31e1ef570cd6a9e029b71bd0f2770/href">https://medium.com/media/33a31e1ef570cd6a9e029b71bd0f2770/href</a></iframe><p>As long as I put my test code within the <em>ZippyEnvironment</em> block, I’m assured that I have access to my Zippy user and that the user will be removed when the test is completed. Note that since we are using <em>ensure</em> we are assured that users will be deleted even if the test fails or if an exception is raised.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cabed948807" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>