<?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 Joseph Chu on Medium]]></title>
        <description><![CDATA[Stories by Joseph Chu on Medium]]></description>
        <link>https://medium.com/@josephchuky?source=rss-391e961624a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XMOoH6apX-tX52cm-qgskw.png</url>
            <title>Stories by Joseph Chu on Medium</title>
            <link>https://medium.com/@josephchuky?source=rss-391e961624a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 03:41:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@josephchuky/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[Automation QA Toolbox 101: Build an Event-Driven Streaming Test Execution Monitoring Platform for…]]></title>
            <link>https://medium.com/test-go-where/automation-qa-toolbox-101-build-an-event-driven-streaming-test-execution-monitoring-platform-for-72287dc3c4e9?source=rss-391e961624a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/72287dc3c4e9</guid>
            <category><![CDATA[influxdb]]></category>
            <category><![CDATA[testing-framework]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[metrics-and-analytics]]></category>
            <category><![CDATA[test-automation]]></category>
            <dc:creator><![CDATA[Joseph Chu]]></dc:creator>
            <pubDate>Sun, 13 Feb 2022 02:09:55 GMT</pubDate>
            <atom:updated>2022-02-13T02:09:55.515Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Automation QA Toolbox 101: Build an Event-Driven Streaming Test Execution Monitoring Platform for Better Observability</strong></h3><h3>Background</h3><p>One of the most essential key metrics we use to evaluate the ROI of test automation is test stability. Currently all of the test reports/tools/plugins in the test community calculate the test pass rate based on the latest test result. However test stability should be an overall test pass rate which needs to be calculated based on test execution data in a given sliding window.</p><p>Say we have around 40K automated test cases and we have around 100K test executions every day (which means for each test case it gets executed up to three times within 24hours). To evaluate test stability, we cannot just simply calculate the test pass rate based on the latest test output because if we consider the below scenarios:</p><ol><li>At 2AM, the nightly run executes 40K cases with 4K failed cases</li><li>At 9AM. We conduct nightly triaging for the failed cases execute another round of 40K cases with 2K failed cases</li><li>During working hours, we use AT to help sign off feature testing tickets and execute yet another 40K cases with 0.5K failed cases</li></ol><p>The current test report tools will just provide the pass rate for 3) with a pass rate of (40K-0.5K) / 40K*100% = 98.75%. This pass rate is just a real-time pass rate for that batch of execution which does not reflect our test stability correctly. If we use 24hours as a time window, the overall pass rate should be ((40K-4K) + (40K-2K) + (40K-0.5K) / (40K+40K+40K+) * 100% = 94.5%only.</p><p>Based on the above analysis, we can also conclude that the test pass rate from a single test report really does not tell you much about the test stability. On the contrary, if you look at a whole set of test reports in a given time window, then you can fully understand the test stability. This conclusion challenges us to find a way to accumulate our each and every test report in a sliding window and then conduct calculations based on it.</p><p>To tackle this challenge, let us now try to find a way to accumulate test reports in the past 24hours. Given that every day we have 100K test executions, we observe that our test results are actually just like streaming data. If we consider each of the test case results as an event, that essentially means we are building a event-driven solution which is capable of collecting streaming data in a sliding window (24hours) to be processed and eventually show the real-time stats (real time test stability in 24hours).</p><h3>Solution Design</h3><h4>~~INFLUXDB~~</h4><p>Before we go further, let us take a step back and understand what is influxDB and why we use it. One of the main reasons is that it is a <strong>time-series database</strong>, a.k.a data with timestamps which allows for analyzing and monitoring time-sensitive data. On top of that, InfluxDB is also able to handle <strong>high I/O load </strong>which allows for efficient retrieval and even real-time feedback. So influx DB is perfectly matched with our needs to stash our streaming event data (test results).</p><p>Here are some other terms which would help in understanding how it pieces together as we discuss further how it is set up.</p><ul><li><strong>Measurement: </strong>The group of data that uses a similar data storage structure. Think of it as a subset of your database.</li><li><strong>Fields: </strong>A required component consisting of a <em>key:value</em> pair that stores the data you want.</li><li><strong>Tags:</strong> Similar to fields, it is also a <em>key:value</em> pair that stores data. The main difference is that tags are indexed data. Which also translates to it being processed much faster as compared to fields when querying. As such, it is important to consider which fields to be used as tags.</li></ul><h4>~~GRAFANA~~</h4><p>So we choose influx DB to stash our real-time test results, now we need to visualize data with a dashboard for better observability. Grafana is an out-of-box dashboard solution which empowers you to query, visualize, alert on and understand your metrics no matter where they are stored. Create, explore, and share beautiful dashboards with your team and foster a data driven culture</p><h4>~~KICK-OFF~~</h4><p>Now let us see how we can easily do so using a base architecture setup that includes <strong>Grafana</strong> and <strong>InfluxDB</strong>. Test results from all our tests are consolidated in a DB which acts as a source of data for Grafana to draw upon for display.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*_a6xidPkaI-DdoQw" /></figure><h4>~~INITIAL-SETUP~~</h4><p>To begin, there would be a need to install both Grafana and InfluxDB with instructions that can be easily followed and found <a href="https://grafana.com/docs/grafana/latest/getting-started/getting-started-influxdb/">here for Grafana</a> and <a href="https://docs.influxdata.com/influxdb/v1.8/tools/shell/">here for InfluxDB</a>. InfluxDB will act as a data storage which Grafana will tap into to further process and display as according to how you would like it to be.</p><p>After the installation, we would need to allow your Grafana to access the data in your InfluxDB via HTTP. Simply input the configurations of your influxDB under</p><pre>Grafana → Configuration → Data Sources</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w9E13Ct-B8meWqaxilqhHw.png" /><figcaption>Linking InfluxDB to Grafana</figcaption></figure><p>With that, your base setup is complete!</p><h4>~~Gathering Test Results~~</h4><p>Next let us store some data in our InfluxDB. Here we demonstrate a simple <strong>InfluxDB Client in Golang</strong> that can be easily inserted anywhere in your code or processes to gather results of your automated test.</p><pre>import influxdb2 &quot;github.com/influxdata/influxdb-client-go/v2&quot;</pre><pre>func GetInfluxClient() influxdb2.Client {<br>   return influxdb2.NewClient(InfluxUrl<strong>, </strong>InfluxToken)<br>}</pre><p>We then write the function which uses this client to push one datapoint into our InfluxDB.</p><pre>func WriteToInflux(measurement string<strong>, </strong>tags map[string]string<strong>, </strong>fields map[string]interface{}) error {<br>   ctx := context.Background()</pre><pre>   <strong>//Init Base Client</strong><br>   client := GetDefaultInfluxClient() <br>   defer client.Close() </pre><pre>   <strong>//Init write client from base </strong><br>   writeClient := client.WriteAPIBlocking(InfluxOrg<strong>, </strong>InfluxBucket)</pre><pre>   <strong>//Creating a new point based on input parameters</strong><br>   p := influxdb2.NewPoint(measurement<strong>, </strong>tags<strong>, </strong>fields<strong>, </strong>time.Now())<br>   <br>   <strong>//Writing to InfluxDB</strong><br>   err := writeClient.WritePoint(ctx<strong>, </strong>p)<br>   if err != nil {<br>      log.Println(&quot;Error when writing to Influx: &quot;<strong>, </strong>err<strong>, </strong>&quot;for measurement: &quot;<strong>, </strong>measurement)<br>      return err<br>   }<br>   return nil<br>}</pre><p>And that is it, as straightforward as that! Now all we have to do is just place this function wherever we want to collect data for example in an automated test like this:</p><pre>func Test_getApiExample(t *testing.T) {</pre><pre>  <strong>//Initialisation</strong><br>  service, client, err := serverA.New()<br>  assert.NoError(t, err)</pre><pre><strong>  //Example API Call</strong><br>  req := service.BuildDefaultReq()<br>  resp, err := client.SendApi(req)<br>  assert.NoError(t, err)</pre><pre>  expectedResp := service.GetDefaultResp()<br>  assert.EqualValues(t, expectedResp, resp)</pre><pre><strong>//Store API Response in InfluxDB </strong><br>  err := WriteToInflux(<br>      &quot;all_test_results&quot;<strong>, <br>      </strong>map[string]string{&quot;run_id&quot;: req.GetTimeId()}<strong>, <br>      </strong>map[string]interface{} {<br>        &quot;case&quot;:             &quot;Test_getApiExample&quot;         <br>        &quot;error_msg&quot;:        resp.GetErrorMsg()<strong>,<br>        </strong>&quot;error_code&quot;:       resp.GetErrorCode()<strong>,<br>        </strong>&quot;exec_time&quot;:        resp.GetExecTime()<strong>,<br>        </strong>&quot;status&quot;:           resp.GetStatus<strong>,<br></strong>})</pre><p>In short, we simply call the WriteToInflux function whenever we want to input a datapoint with the corresponding measurement (“all_test_results”), tags (“run_id”) and fields (“error_msg”, “error_code”, “exec_time”, “status” and “case”).</p><h4>~~DISPLAYING ON GRAFANA~~</h4><p>Now to the main purpose of all the preparations before this, we will first create a new Dashboard on Grafana which can be found on the side-nav bar in your grafana page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*0_s0_spdmyvxEE73OO6QZQ.png" /><figcaption>Creating a new Dashboard</figcaption></figure><p>We then create a new panel which is found in the top-nav bar of your newly created dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1nUt0qcUjyeIike9rS8qnw.png" /><figcaption>Creating a new panel</figcaption></figure><p>We then choose how we want to display. Grafana itself offers many ways to display the data such as Stat, Time-series, Graph, Gauge, Bar-gauge, Table, Text, Pie-chart, List, Logs and more.</p><p>Then we pair the above configuration with the data we want to display from the query section of in the panel which can either be in Flux query, which is very similar to the commonly known SQL language, or a click-drag-drop UI as provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LntP--sZkNMD2O2P1ORg2A.png" /><figcaption>Flux query language</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dF-_95QECDo-II8ypyurXQ.png" /><figcaption>Click-Drag-Drop UI provided to query our InfluxDB</figcaption></figure><p>With the basics down, let us explore how we can showcase our test results and some possible uses of such display metrics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSu9yDfxut3SbNvPDE8g3Q.png" /><figcaption>Stat Data showing the total number test cases and its status</figcaption></figure><p>We can easily obtain the total number of ATs which have ran in total within a certain time frame, letting us know either the number of cases its status.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*kaGr5w5xLM8Yz4ci5N7zGg.png" /><figcaption>Pie-chart showing % of total passed, failed and skipped cases</figcaption></figure><p>Another way to present such stat data might be through a pie-chart as above which gives a pictorical overview of the % of your test status. To expand upon this information further, we can also generate a time-series representation to see when the ATs are used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S83ggj-286KyyHl_WUhQkQ.png" /><figcaption>Time series of the status of the ATs ran</figcaption></figure><p>As can be interpreted , nightly regressions are running from about 10pm to 8am. The ATs are also heavily used around 3 to 6pm, as well as 12pm which goes to show that QAs are actively using the ATs to assist in their testing, be it for full or partial regression, and even initial checks of new product code additions or edits.</p><p>On the other hand, we can use the above graph to see the availability of the test infrastructure which can suggest where new ATs should be added. For example, somewhere between 12.30am to 1am or around 4.30am to 5.30am is a good empty slot which would decrease the chances of conflicting tests.</p><p>Having seen all the different graphical representations, you might be surprised to find that the Flux query passed to obtain the data for each of them is the same for all the displays shown above!</p><p>1. Total Cases:</p><pre>COUNT(“cases”) FROM “all_test_results” AND $timeFilter GROUP BY time($__interval) fill(null)</pre><p>2. Cases Passed:</p><pre>COUNT(“status”) FROM “all_test_results” WHERE (“status”=&#39;success&#39;) AND $timeFilter GROUP BY time($__interval) fill(null)</pre><p>3. Cases Failed:</p><pre>COUNT(“status”) FROM “all_test_results” WHERE (“status”=&#39;failed&#39;) AND $timeFilter GROUP BY time($__interval) fill(null)</pre><p>4. Cases Skipped:</p><pre>COUNT(“status”) FROM “all_test_results” WHERE (“status”=&#39;skipped&#39;) AND $timeFilter GROUP BY time($__interval) fill(null)</pre><p>We can observe that with a few simple queries, we can generate a myriad of different ways to present our data quickly and easily. We can also look at this from another point of view such as <strong>case count</strong> or <strong>pass rate across time</strong>. Such graphs can derived from our current data gives us a clearer overview of the stability and quantity of ATs ran during certain points of time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ivw-_ttEkQ4-y_9WXyfkGg.png" /><figcaption>Case count and Pass rate across time</figcaption></figure><p>Furthermore, with some small tweaks and adjustments, we can even break down the data into smaller components such as each individual API, server or even aggregate the data across different services or teams to get a larger overview, letting us better and quickly understand at a glance our test infrastructure, condition and status.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1oyB0mQC3w-btNxnFq4Nw.png" /><figcaption>Total cases ran across time broken down by service then by APIs</figcaption></figure><p>Grafana also supports the detailed configurations such as the components of a graph (axes, bars, lines, area, legend, line width etc.) with options to <strong>override</strong> some default display settings if necessary and <a href="https://grafana.com/docs/grafana/latest/panels/transformations/"><strong>transformation </strong>of your data</a> including changing of display data via joining, calculations, ordering, hiding or renaming.</p><h4>~~MOVING FORTH~~</h4><p>With the basics down and the metrics up, we then turn to look at the more minute configurations and some important things to note when doing your basic setup which are of course not exhaustive.</p><p>1. <strong>Retention Policy</strong>: How long data is kept in the DB including replicates (if any) and shard duration. By default, it is kept infinitely but that would be a waste of resources, space and processing powers. One might consider how relevant such test results or any sort of data will be as time passes. More information about this can be found <a href="https://docs.influxdata.com/influxdb/v1.8/query_language/manage-database/#retention-policy-management">here</a>.</p><p>2. <strong>Managing Database</strong>: As with all databases, knowing how to manage it is as important as knowing how to use it. To check on the data not only through Grafana but also through <strong>influx-cli </strong>can help provide more clarity and consideration when building your own dashboard pipeline. More information about this can be found <a href="https://docs.influxdata.com/influxdb/v1.8/query_language/manage-database/">here</a>.</p><p>3. <strong>Continuous Query</strong>: InfluxDB supports continuous query which sends queries automatically and periodically. While the usage of this is for the more advanced, it offers amazing versatility to the usage of data especially when some are dependent or nested in another. More information about this can be found <a href="https://docs.influxdata.com/influxdb/v1.8/query_language/continuous_queries/">here</a>.</p><p>4. <strong>Grafana Plugins</strong>: Grafana is also supported by plugins which not only offers itself as a more powerful display tool, but also integrations with other services such as Jira, Gantt and even other types of DBs. All their available plugins can be found <a href="https://grafana.com/grafana/plugins/">here</a>.</p><p>5. <strong>Integrations</strong>: With the basic architecture, we can add on other services along its flow or add it to another, easily integrating it into any part of our pipeline to track test data and metrics. One such example would be to use the influx client as an external tool which collects and constantly updates DB as each Jenkins Job is ran.</p><p>With that, we have gone through how we can setup a simple Grafana dashboard using InfluxDB and its flexibility for displaying test data in several ways depending on the story you want to tell. Once we are able to use the data obtained during testing and usage of our ATs , will we then be able to know where to focus on and improve our testing components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*VMQDKRlXkwQRJu5uP3qfQg.jpeg" /></figure><p>As obvious as it is, let us also emphasise the importance of ensuring that your data and metrics are relevant, accurate and useful for it would truly be done “for nothing” should it be otherwise.</p><p>Lastly, we hope this article will not only be useful for introducing how to measure and display test data, but also for any types of data which might be of interest to be measured. The way <strong>you want</strong> to measure, track and present your data is limited only by your <strong>imagination</strong>.</p><p>Big thanks to <a href="https://medium.com/u/76a141c7409c">Huang Luohua</a> for his guidance throughout and <a href="https://medium.com/u/729ce80c466f">Elaine Chong</a> for her initiative in kicking off this project as well as assistance provided throughout!</p><p>All of the codes can be cloned here: <a href="https://github.com/luohuahuang/junit-influx-client">https://github.com/luohuahuang/junit-influx-client</a></p><p>Go wild.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72287dc3c4e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/test-go-where/automation-qa-toolbox-101-build-an-event-driven-streaming-test-execution-monitoring-platform-for-72287dc3c4e9">Automation QA Toolbox 101: Build an Event-Driven Streaming Test Execution Monitoring Platform for…</a> was originally published in <a href="https://medium.com/test-go-where">test-go-where</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automation QA Toolbox 101: Cache]]></title>
            <link>https://medium.com/test-go-where/automation-qa-toolbox-101-cache-be01a3d994fa?source=rss-391e961624a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/be01a3d994fa</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[testing-tools]]></category>
            <category><![CDATA[automation-tools]]></category>
            <dc:creator><![CDATA[Joseph Chu]]></dc:creator>
            <pubDate>Sun, 19 Sep 2021 14:52:31 GMT</pubDate>
            <atom:updated>2021-09-20T14:41:43.873Z</atom:updated>
            <content:encoded><![CDATA[<p>This series aims to explore the various commonly used tools in the tech environment and infrastructure with a focus of its application and use in the context of an automation and from an automation QA point of view.</p><h3>Cache</h3><p>Cache can be seen as an alternate memory space to traditional databases that provides a quicker, faster and more efficient way of accessing stored data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mJIoXiM6n3PCrtAPRqNVg.png" /></figure><p>The diagram above shows one of the many examples of using a cache in accessing stored data which not only reduces the processing load on the database, but also speeds up the overall performance of the service as information can be retrieved quicker and with <strong>higher stability</strong> with <strong>increasing “queries-per-second”</strong>. Many different variations can be branched out or adapted from using cache which can easily fit your needed use case.</p><h3>Why is it important for Automation QA</h3><p>With the many advantages of using a cache and proper management of its disadvantages, it is a popular option for many services and APIs which then also becomes a testing point for QAs downstream.</p><p>Knowing how to use a cache thus becomes an important skillset as an automation QA who has to ensure that he is writing the daily automated tests accurately and correctly.</p><p>As such we will be going through how to manipulate a redis cache which is also known for its data-type specificstorage as compared to other types of cache.</p><h3>Simple Example of using Cache</h3><p>To picture how cache works, just think of a normal key-value storage such as a has Dictionary or Hashmap. So we first start by defining how we will be connecting to a redis storage space with a specific port number for our specific cache via TCP.</p><pre>import &quot;github.com/go-redis/redis/v7&quot;</pre><pre>func main() {<br>    redisOption := &amp;redis.Options{<br>        Network: &quot;tcp&quot;<strong>,<br>        </strong>Addr:    redisAddr<strong>,<br>        </strong>}<br>    redisCli := redis.NewClient(redisOption)</pre><p>We do a simple verification that our connection to the cache is valid and working with a ping-pong test.</p><pre>    pong, err := redisCli.Ping().Result()<br>    if err != nil || pong != &quot;PONG&quot; {<br>        panic(err)<br>    }</pre><blockquote>Now let’s paint the context of our example here. Imagine we have this cache which stores a simple diary log of your activities under the key date|hour|minutes . Let us store some diary logs in our cache.</blockquote><pre>    err = redisCli.Set(&quot;29062021|12|30&quot;, &quot;Neko keeps meowing for food, feed.&quot;, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    err = redisCli.Set(&quot;29062021|15|0&quot;, &quot;Neko shattered my glass cup&quot;, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    err = redisCli.Set(&quot;29062021|5|30&quot;, &quot;Awoken by Neko jumping on me&quot;, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><p>With that, we successfully stored 3 beautiful memories with the house cat Nekoon 29th June 2021:</p><ul><li>Feed pet cat Neko at 1230</li><li>Neko knocked my favourite glass cup off the table and broke it at 1500</li><li>Neko jumped on me while I was sleeping at 0530</li></ul><p>Having stored them in the cache, we would also need a way to retrieve and relieve these wonderful moments with Neko. For example, the time when she broke your favourite cup 😇</p><pre>activity, err := redisCli.Get(&quot;29062021|15|0&quot;).Result()<br>	if err != nil {<br>	    panic(err)<br>	}<br>	fmt.Println(activity)//&quot;Neko shattered my glass cup&quot;</pre><h3>Complete Code Example</h3><pre>import &quot;github.com/go-redis/redis/v7&quot;</pre><pre>func main() {<br>    redisOption := &amp;redis.Options{<br>        Network: &quot;tcp&quot;<strong>,<br>        </strong>Addr:    redisAddr<strong>,<br>        </strong>}<br>    redisCli := redis.NewClient(redisOption)</pre><pre>    <strong>// Store data in Cache</strong><br>    err = redisCli.Set(&quot;29062021|12|30&quot;, &quot;Neko keeps meowing for food, feed.&quot;, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    err = redisCli.Set(&quot;29062021|15|0&quot;, &quot;Neko shattered my glass cup&quot;, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    err = redisCli.Set(&quot;29062021|5|30&quot;, &quot;Awoken by Neko jumping on me&quot;, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre><strong>    // Retrieve Data in Cache</strong><br>    activity, err := redisCli.Get(&quot;29062021|15|0&quot;).Result()<br>	if err != nil {<br>	    panic(err)<br>	}<br>	fmt.Println(activity) //&quot;Neko shattered my glass cup&quot;</pre><h3>Versatility of using Cache</h3><p>Now the dirry is all great except but as much as I wish to, life does not just revolve around cats right? What if there is a need to store more complex information that goes beyond just a simple string??</p><pre>type DiaryLog struct {<br>    Event            string<br>    EventCategory    int32<br>    Location         string<br>    ActionTaken      string<br>    Cost             int32<br>    Troublesome      bool<br>}</pre><p>Next let’s include some helper functions to better organise our code.</p><pre>func GetKey(date, hour, minute int) string {<br>    return fmt.Sprintf(&quot;%v|%v|%v&quot;, date, hour, minute)<br>}</pre><p>To store the struct in our cache, we first massage it into a byte array (instead of a string as above) through a marshaling step before storing them in our cache.</p><pre>func main() {<br>    log := &amp;DiaryLog{<br>        Event:          &quot;Neko shattered my glass cup&quot;<br>        EventCategory:  int32(19)<br>        Location:       &quot;home&quot;<br>        ActionTaken:    &quot;Forgive Neko, clean broken pieces&quot;<br>        Cost:           int32(56)<br>        Troublesome:    true<br>    }<br>    key := GetKey(29062021, 15, 0)<br>    <br>    logByte, err := proto.Marshal(log)<br>    if err != nil {<br>        panic(err) <br>    }</pre><pre>    err = redisCli.Set(key, logByte, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><p>To retrieve and read our data, we simply do the same 2 steps, but in reverse!</p><pre>    memory := &amp;DiaryLog{}</pre><pre>    dataArray, err := redisCli.Get(key).Bytes()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    err = proto.Unmarshal(dataArray, memory)<br>        if err != nil {<br>	panic(err)<br>    }</pre><pre>    fmt.Println(memory)</pre><p>See the similarities in the process flow? Exactly. If you realise, we are only changing the type of data we store here from a string, to a byte array representing our given struct.</p><h3>Complete Code Example</h3><pre>type DiaryLog struct {<br>    Event            string<br>    EventCategory    int32<br>    Location         string<br>    ActionTaken      string<br>    Cost             int32<br>    Troublesome      bool<br>}</pre><pre>func GetKey(date, hour, minute int) string {<br>    return fmt.Sprintf(&quot;%v|%v|%v&quot;, date, hour, minute)<br>}</pre><pre>func main() {<br>    log := &amp;DiaryLog{<br>        Event:          &quot;Neko shattered my glass cup&quot;<br>        EventCategory:  int32(19)<br>        Location:       &quot;home&quot;<br>        ActionTaken:    &quot;Forgive Neko, clean broken pieces&quot;<br>        Cost:           int32(56)<br>        Troublesome:    true<br>    }<br>    key := GetKey(29062021, 15, 0)</pre><pre>    <strong>//Marshal data into a byte array</strong><br>    logByte, err := proto.Marshal(log)<br>    if err != nil {<br>        panic(err) <br>    }</pre><pre>    <strong>//Store in Cache</strong><br>    err = redisCli.Set(key, logByte, 0).Err()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    memory := &amp;DiaryLog{}.  </pre><pre>    <strong>//Get byte array data from cache</strong><br>    dataArray, err := redisCli.Get(key).Bytes()<br>    if err != nil {<br>	panic(err)<br>    }</pre><pre>    <strong>//Unmarshal data to defined struct</strong><br>    err = proto.Unmarshal(dataArray, memory)<br>        if err != nil {<br>	panic(err)<br>    }</pre><pre>    <strong>//Profit</strong><br>    fmt.Println(memory)</pre><h3>Troubleshooting</h3><p>One issue one might have with cache is accessibility. Sometimes, we just need an alternate way to do things aside from code. Fret not, for similarly, there are also many available tools to access cache. One of which that is most readily available is the redis-cli through our terminals. We simply access the cache by typing the command which specifies the host and port of our cache</p><pre>redis-cli  -h &lt;ipaddress&gt; -p &lt;port&gt;</pre><ul><li>if value is of type <strong>string → </strong>GET &lt;key&gt;</li><li>if value is of type <strong>hash →</strong> HGETALL &lt;key&gt;</li><li>if value is of type <strong>lists</strong> → LRANGE &lt;key&gt; &lt;start&gt; &lt;end&gt;</li><li>if value is of type <strong>sets →</strong> SMEMBERS &lt;key&gt;</li><li>if value is of type <strong>sorted sets →</strong>ZRANGEBYSCORE &lt;key&gt; &lt;min&gt; &lt;max&gt;</li></ul><p>If you aren’t sure of your data type, simply use the command type &lt;key&gt; to find out.</p><p>Here we discussed the usage of a Redis Cache through Golang which can be easily adapted to your use case with the many other libraries available and also other types of cache, that follows a similar conceptual flow but with different context, and specifications and syntax.</p><p>Check out another popular tool, ETCd, which we often encounter during testing introduced by Luohua <a href="https://medium.com/test-go-where/use-etcd-service-discovery-in-test-infra-402900f64bf7">here</a>!</p><p><em>~ Happy testing ~ Stay tuned to the next toolbox discussion~*</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be01a3d994fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/test-go-where/automation-qa-toolbox-101-cache-be01a3d994fa">Automation QA Toolbox 101: Cache</a> was originally published in <a href="https://medium.com/test-go-where">test-go-where</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing Automated Tests with the Four-Phase Test Pattern]]></title>
            <link>https://medium.com/test-go-where/developing-automated-tests-with-the-four-phase-test-pattern-b5fe05c24c67?source=rss-391e961624a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5fe05c24c67</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[quality-assurance-testing]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Joseph Chu]]></dc:creator>
            <pubDate>Sat, 14 Aug 2021 10:07:47 GMT</pubDate>
            <atom:updated>2021-08-14T10:34:11.247Z</atom:updated>
            <content:encoded><![CDATA[<p>So one fine day, after waking up to the beautiful sound of male birds doing their mating calls in the morning (yes, this is true), you decide that it is time to write some automated tests.</p><p>Writing individual isolated tests sounds easy enough, but have you considered how your tests will run in an automation environment? What are the things to consider when writing one, or even, more simply put, how should we begin?</p><h3>— Test Structure —</h3><p>We begin by setting a structure. Why structure? Let’s talk individual. A structure provides a guide and skeleton for you to frame your thought process. It breaks down your writing into blocks which can be easily filled in given the context of the test. It also allows you to easily debug by zooming in to that particular section of your structured automated test.</p><p>Importance of using a structure is even more important when working as a team where such tests are managed not only by yourself. A structure would allow your team members to easily pick up what is happening in each part of your code without having to spend time understanding the whole context again.</p><blockquote>Convention over Configuration</blockquote><p>Adapted from a software development concept, convention, provided for by a structure, allows for things to progress as the general context can be understood from the convention instead of anew. This improves the accessibility and ease of use for what you have written which is beneficial not only in a collaborative setting, but also for yourself should you need return to this piece of work in the future.</p><figure><img alt="Convention over Configuration" src="https://cdn-images-1.medium.com/max/614/1*a0BdbnRUpHaoqH7nSLRrPg.png" /><figcaption>Definitely NOT a situation we want to put ourselves in..</figcaption></figure><p>Back to the question then of how should we write an automated test? We turn to the Four-Phase Test structure introduced in the book —<strong> xUnitTest Patterns</strong> which consists of:</p><ol><li>Setup</li><li>Exercise</li><li>Verify</li><li>Teardown</li></ol><h3>— SETUP —</h3><p>The first phase initializes and puts in place everything that is needed to obtain our desired outcome. We begin by stating clearly what are the variables used and changed in this test.</p><p>Before we move on, let’s paint some context to our automated test we will be writing.</p><blockquote>Let’s imagine we have a simple cat-slave service that provides an expected “action” or return of serve cat food when a request containing meow is called and there are available cat food, buys cat food if not and pets cat otherwise.</blockquote><pre><strong>var (<br>    ServeMasterSomeFood = &quot;Serve Cat Food&quot;<br>    GiveMasterSomePets = &quot;Pets Cat&quot;<br>    BuyFoodForMaster = &quot;Buy Cat Food&quot;<br>)</strong></pre><pre><strong>func ServeCatMaster(cmd *Request) (*Response, err) {<br>    resp := GetDefaultResponse()<br>    if cmd.GetCommand == nil {<br>        resp.ErrorCode = &quot;2&quot;<br>        return resp, fmt.Error(&quot;command cannot be nil&quot;)<br>    if </strong><strong>strings.Contains(cmd.GetCommand(), &quot;meow&quot;) {<br>        if HaveCatFood {<br>        resp.Action = ServeMasterSomeFood<br>            return resp, nil<br>        }<br>        resp.Action = BuyFoodForMaster<br>        return resp, nil<br>    resp.Action = GiveMasterSomePets<br>    return resp, nil<br>}</strong></pre><p>where the function HaveCatFood is a simple check to see if there are cat food at home. We then want to test the functionality of this cat slave in the event where:</p><ol><li>There is cat food available</li><li>The cat meows</li></ol><pre><strong>func Test_cat_slave_serve_cat_food(t *testing.T) {<br>    var (<br>        newCommand = &quot;give me food meow&quot; <br>        availableCatFood = int32(999)<br>        originalCatFood int32</strong><em>// Storage for tear-down<br>        </em><strong>expectedResponse = ServeMasterSomeFood<br>    )</strong></pre><pre><strong>...</strong></pre><p>We then initialize the rest of the variables which are required for the test to run. This might include getting the basic parameters of the test, defining how the API or service we are testing is called and changing the test input to one that suits our current test conditions.</p><pre><strong>...</strong></pre><pre><em>//load basic configuration for cat-slave</em><strong><br>Item = Config.Test[&quot;Cat-slave&quot;]</strong></pre><pre><strong>err := Item.init() </strong><em>//loads other dependencies for cat-slave to function e.g money, time, energy</em><strong><br>assert.NoError(t, err) </strong><em>//error handling for initialization</em></pre><pre><strong>req := Item.GetDefaultRequest() </strong><em>// Get default req</em><strong><br>req.Command = newCommand </strong><em>//customizing request command</em></pre><pre><strong>...</strong></pre><p>After preparation of our request parameters, we move on to our data preparation for expected response.</p><p>In a test environment, we often have to mock data that will be processed by the service or API, and this is exactly what we are doing here — mocking data and returns. Along with setting up the mocked data, we also store the original data for use in tear down later. Below is a pseudo example of changing the variable type of the first item in the database that was initialized above so that it will be returned.</p><pre>...</pre><pre><strong>ItemsAtHome, err := Item.GetAllItemsAtHome()<br>assert.NoError(t, err)<br>originalCatFood = ItemsAtHome.GetCatFood()</strong><em>//Stores original Catfood amount</em></pre><pre><em>//Changing number of cat food available at home</em><strong><br>err := Item.ChangeCatFoodAmountAtHome(availableCatFood)<br>assert.NoError(t, err)</strong></pre><pre><em>//&lt;&lt;INSERT TEARDOWN FUNCTION HERE&gt;&gt; Will be further explained below. </em></pre><pre>...</pre><p>This section clearly shows all the settings we need to obtain our expected response from exercising this test: the request and the requested.</p><h3>— EXERCISE —</h3><p>With all preparations due, it is time to conduct our test by calling the API, or interacting with the system we are testing, with our set parameters which, should then give us our mocked data as set-up before this.</p><pre><strong>...</strong></pre><pre><em>//Calling the Cat Slave API</em><strong><br>resp, err := ServeCatMaster(req)<br>assert.NoError(t, err)</strong></pre><pre><strong>...</strong></pre><h3>— VERIFY —</h3><p>As with all tests, we need to verify the results after conducting it. In this case, we check for our desired outcome in the response variable: resp.</p><pre>...</pre><pre>//Checking our response<strong><br>statusCode := Item.Assert(resp, expectedResponse)<br>assert.Equal(t, codePass, statusCode)</strong></pre><pre><strong>...</strong></pre><p>To further illustrate, an example of the <em>assert function</em>, which we parse our response in, above can be as such:</p><pre><strong>var (<br>    codePass             int32 = 0<br>    codeFailError        int32 = 1<br>    codeIncorrectCommand int32 = 2<br>)</strong></pre><pre><strong>func (test *Item) Assert(resp *Response, expectedResponse) int32 {<br>    if resp.GetErrorCode != 0 {<br>        return codeFailError<br>    } else if {<br>        resp.GetCommand != expectedResponse {<br>        return codeIncorrectCommand<br>   return codePass</strong></pre><p>We first check if there are any errors returned by the API call, then check whether the response is what we desired (contains items of type == cat in the database).</p><h3>— TEARDOWN —</h3><p>Finally, we conduct housekeeping for our automated test by ensuring that all changed variables in the database are returned back to its original state. This is to ensure that subsequent automated tests are not affected by any other variables changed in prior tests and also that our tests does not potentially leave behind any “dirty data” which might increase instability.</p><pre><strong>defer func() {<br>    err := Item.ChangeCatFoodAmountAtHome(originalCatFood)<br>    assert.NoError(t, err)<br>}()</strong></pre><p>where originalType is obtained above in “Setting up Test Data”.</p><h3>— COMPLETE EXAMPLE —</h3><pre><strong>func Test_cat_slave_serve_cat_food(t *testing.T) {<br>    var (<br>        newCommand = &quot;give me food meow&quot; <br>        availableCatFood = int32(999)<br>        originalCatFood int32</strong><em><br>        </em><strong>expectedResponse = ServeMasterSomeFood<br>    )<br>    Item = Config.Test[&quot;Cat-slave&quot;]<br>    err := Item.init() <br>    assert.NoError(t, err)</strong></pre><pre><strong>    req := Item.GetDefaultRequest()<br>    req.Command = newCommand</strong></pre><pre><strong>    ItemsAtHome, err := Item.GetAllItemsAtHome()<br>    assert.NoError(t, err)<br>    originalCatFood = ItemsAtHome.GetCatFood()</strong></pre><pre><strong>    err := Item.ChangeCatFoodAmountAtHome(availableCatFood)<br>    assert.NoError(t, err)</strong></pre><pre><strong>    defer func() {<br>        err := Item.ChangeCatFoodAmountAtHome(originalCatFood)<br>        assert.NoError(t, err)<br>    }()</strong></pre><pre><strong>    resp, err := ServeCatMaster(req)<br>    assert.NoError(t, err)<br>    statusCode := Item.Assert(resp, expectedResponse)<br>    assert.Equal(t, codePass, statusCode)</strong></pre><p>Do note that the teardown function is placed just below our set-up, such that we can easily affirm that we are indeed administering our housekeeping properly.</p><blockquote>It is important for the test reader to be able to quickly determine what behavior the test is verifying.</blockquote><p>Here we introduced and discussed the usage of the four-phase pattern for writing automated tests which you can further build on to fit your use case. Writing automated tests using such a pattern also helps keep our testcase focused and concise. It also makes certain that the person writing the automated test do not have overlapping<strong> “single condition tests” </strong>which not only needlessly increases the complexity of your code, but also obscures the results of our tests and root cause analysis in the event that the test fails.</p><p>For example, these can be easily caught when we find ourselves repeating a certain step of the four-phase pattern in our automated test such as exercising multiple times using a different request multiple times within the same test checking for change.</p><p>In conjunction with this article, check out this relevant <a href="https://medium.com/test-go-where/test-development-patterns-and-anti-patterns-78820e1802df">article on coding practices</a> when writing automated tests by <a href="https://medium.com/u/ba0af76158fe">Hui Ching Lim</a></p><p><em>*~ Happy testing ~ Till next time~*</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5fe05c24c67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/test-go-where/developing-automated-tests-with-the-four-phase-test-pattern-b5fe05c24c67">Developing Automated Tests with the Four-Phase Test Pattern</a> was originally published in <a href="https://medium.com/test-go-where">test-go-where</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Taste of Automation Testing]]></title>
            <link>https://medium.com/test-go-where/first-taste-of-automation-testing-e05787cac9c0?source=rss-391e961624a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e05787cac9c0</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[software-test-automation]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[automation-testing]]></category>
            <dc:creator><![CDATA[Joseph Chu]]></dc:creator>
            <pubDate>Sun, 08 Aug 2021 08:33:56 GMT</pubDate>
            <atom:updated>2021-08-08T08:33:56.519Z</atom:updated>
            <content:encoded><![CDATA[<p>Automation testing (AT) is often sought as a Continuous Integration, Continuous Development (CI/CD) solution to increased efficiency, effectiveness and higher quality for software products. Its application and usage, however, goes way beyond just “automating tests”. Stepping into Shopee as an AT QA has put this into perspective as I not only become part of the whole software development lifecycle (SDLC) but also partake in the development of AT at Shopee.</p><p>So what does automation tests actually entail? Let’s dive into it.</p><h3>Testing Context</h3><p>We first understand the context of the test. Some key questions to be answered here might include:</p><ul><li>What kind of tests are we looking at?</li><li>What is the purpose of the test?</li><li>What is needed for the tests to be carried out?</li><li>What environment is this test carried out in?</li><li>Which part of the whole architecture flow are we zooming in on?</li></ul><p>These will be the foundation knowledge which we build our automated tests on and it is from these that we decide the next course of action to take such as reading code for white-box or grey box testing and deciding what is required to run our tests.</p><h3>Building the Links and Flow Pathways</h3><p>Next we construct the links and set up the proper flow for our own cases based on our context. Some things to take note here are the environment in which we want to run our test cases or how we want to adjust some dependency calls.</p><p>For example, a separate service using a specified environment configuration might need to be set up to achieve the testing target. This might also include microservices such as kafka and etcd in which, its set up is another can of worms that will be discussed in another future article.</p><h3>Writing the Tests</h3><p>As we move to writing the ATs, we follow a framework that has the general flow as follows — initialisation, setting up of data for test, assert and tear down. This general framework not only allows for clarity in our AT flows, but also increases readability and stability. The knowledge and context gathered above will also allow us to know how to set up ATs concisely and neatly, without asserting “too much/too little” or “too general/too specific”.</p><h3>Automating</h3><p>Finally, we move on to the “automation” component where tests and services are configured to run and build periodically or nightly. In Shopee, this is managed mainly by Jenkins infrastructure which has a friendly user interface and allows one to set up automated jobs within <strong>minutes</strong>. The versatility of Jenkins also allows for customisation of your test flow to suit your needs which might include when and where the ATs are run, specific git branch to run and more.</p><p>Once that is set-up, we can take a breather as we hands-off and let our ATs run…<em>or can we</em>?</p><h3>Maintaining</h3><p>Maintaining the ATs we wrote and built is another crucial step in the whole SDLC. ATs are supposed to signal when changes affect a feature’s functionality, which might have reasons stemming from there being a bug, change in logic or maybe a deprecated component depending on the business requirement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*IxocUpdSJxZTm7Jb" /></figure><p>Additionally, they might also be because of instability arising from the environment, services or the way ATs are written, such as improper tear down leading to dirty data and asserts which are too specific.</p><p>With the fast pace of changes in, an AT QA should always prioritize maintaining current cases before building more. Unmaintained ATs are hours, or even days, of effort down the drain. Moreover, building on something that is broken will only allow problems to snowball.</p><p>Here we looked at the general flow in generating automated tests which should not be viewed in a linear point of view but should be revisited when necessary. A few high-level thought processes as an Automation QA Engineer are also introduced which will be discussed in-depth in future articles.</p><p><em>~Stay tuned~</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e05787cac9c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/test-go-where/first-taste-of-automation-testing-e05787cac9c0">First Taste of Automation Testing</a> was originally published in <a href="https://medium.com/test-go-where">test-go-where</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>