<?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 William Hartwell on Medium]]></title>
        <description><![CDATA[Stories by William Hartwell on Medium]]></description>
        <link>https://medium.com/@emperor.swanky?source=rss-cb39c6346f09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3MhrUFmT9vlMlQpP</url>
            <title>Stories by William Hartwell on Medium</title>
            <link>https://medium.com/@emperor.swanky?source=rss-cb39c6346f09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:15:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emperor.swanky/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[Some Automated Test Case Best Practices]]></title>
            <link>https://medium.com/@emperor.swanky/some-automated-test-case-best-practices-85ed3931e7bf?source=rss-cb39c6346f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/85ed3931e7bf</guid>
            <category><![CDATA[automated-test-cases]]></category>
            <dc:creator><![CDATA[William Hartwell]]></dc:creator>
            <pubDate>Mon, 30 Sep 2024 12:33:25 GMT</pubDate>
            <atom:updated>2024-10-07T17:31:56.097Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past several years I’ve been developing automated test scripts that run against clinical and research healthcare web applications, and I’ve settled on some best practices that I think will be broadly applicable. These are some thoughts that are largely reminders for myself, but hopefully can provide some insights to someone starting out automating tests of their own.</p><p>Most importantly, <strong>reliability </strong>is key.</p><p>It’s critical that a test case can be relied on to pass when there’s nothing wrong with the application code, and will consistently fail where there’s a genuine code problem. That’s something of an ideal that’s never 100% attainable, but that should always be the goal.</p><p>Here are a few general ways to implement test cases with that goal in mind:</p><h4><strong>Targeted Tests</strong></h4><p>Tests that are targeted to a specific function are preferable over longer sprawling tests that attempt to verify a lot of varied functionality. A test that verifies the proper creation of an entity, should do exactly enough to create that entity and verify it. This way if the test fails, it’s an indication that there’s an issue with that specific piece of functionality. Our earliest tests were long end-to-end tests that would create an entity, verify some elements, configure it, use it to create a new entity, verify some results, and so on.</p><p>When these tests would fail it was challenging to understand precisely where the problems originated. From a glance, it just looked like the whole thing failed, with no indication of whether the problem was creating the first entity, or the next, or some process that was supposed to have been kicked off after the configuration was saved halfway into the test execution. Every failure required in depth analysis.</p><p>Verifying the creation of the first entity in a standalone test makes it easy to see if that specific functionality is working. A second test that creates the first entity, configures settings, and advances the process to a second entity and verifying it can focus on just that purpose, and take for granted that the first test is verifying the first entity. End-to-end tests have value, but they’re not substitutes for targeted testing.</p><h4>Focused Test Steps</h4><p>Every test step in a script should be necessary to testing the target functionality of the test. If a setting isn’t relevant to the target functionality in this test, don’t touch that setting in this test. Tests that include steps that aren’t necessary will fail when there’s a problem with that step, and if that behavior isn’t what you’re interested in, that failure doesn’t actually tell you anything about the target functionality. It may be important to know that there’s an issue with that setting, but that functionality belongs in its own test.</p><p>Every additional step in a test script makes the test more fragile, because it’s an opportunity for that test to fail. You want to try to limit test failures to be relevant to the matter at hand.</p><h4>Isolate Test Users and Data</h4><p>If your application handles multiple users — in the case of our clinical trial apps we had “test patients” — each test case should use a user unique to that case. This way tests being run in parallel wouldn’t interfere by changing test data for a patient that’s also being used in another test case.</p><p>Also, we found it valuable to clean up test data at the beginning of the test, not at the end. A test would begin by deleting any existing data associated with a test patient. Then the test would register that patient in the system, configure it, and then do whatever else was necessary for the purpose of that test. If the clean up steps are at the end, you run the risk of the test failing somewhere in the middle, and never executing the clean up steps. This can leave you in an invalid state to rerun the test without manually cleaning things up first.</p><p>There’s also a distinct issue with the user that the test case uses to login to the application and execute the test steps. It’s important that this user has the same privileges that a typical user of the application will have, and not more (e.g., admin privileges). There may be certain actions that will require additional privileges, but generally, tests should be run with the minimal set of privileges necessary to exercise the target behavior.</p><h4>Don’t Sweat the Seconds</h4><p>There are points in test cases where you need to have the system wait a while for something to happen before moving on. The framework we used had a notion of “smart waits” where you could basically tell the test something like “Click on this link and wait for the page to load” and the test would wait for feedback from the browser that the page had completed loading before moving on to the next step. This way you could guarantee that as soon as the test could safely proceed, it would, and not before.</p><p>But there were times where the smart waits couldn’t be used. For example, some background process needs a few seconds to complete, but there’s no feedback to tell the test that it has completed. We’d need to put in a hard wait to allow that process to finish, and then the test could move on.</p><p>When you’re running a test case while first developing it, you’ll need to run that test over and over as you’re working out the bugs. When you get to a hard wait of, say, 30 seconds, before the test can move on to the next step, having to sit there watching the test do nothing for 30 seconds can be maddening. There’s a temptation to try to get those hard waits as small as possible, just so you don’t have to sit there while running it yourself for the tenth time that day.</p><p>But in the long run, this test case is going to be run many hundreds of times in automated test runs kicked off in the middle of the night, and you’ll review the results the next morning. Whether the hard wait was 5 seconds or 30 doesn’t matter to the system. But if that background process takes 20 seconds every once in a while, the test with a hard wait of 5 seconds will fail every once in a while, even though nothing was wrong the the application code. You’ll waste much more time analyzing those failures and rerunning the failed tests than you would have spent developing the test with a hard wait of 30 seconds in the first place.</p><p>This is only scratching the surface of what I’ve learned so far, while managing our test system. Keeping these principles in mind when setting up a new system, or even just writing a new test script in an existing system, will pay off in the long run.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85ed3931e7bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>