<?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 msporna on Medium]]></title>
        <description><![CDATA[Stories by msporna on Medium]]></description>
        <link>https://medium.com/@michalsporna?source=rss-ba49aac0d247------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Xz0evjPpQzDr-iZiFPO0hA.jpeg</url>
            <title>Stories by msporna on Medium</title>
            <link>https://medium.com/@michalsporna?source=rss-ba49aac0d247------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:31:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michalsporna/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[Treasure hunting in video game testing: a tale about using test coverage tool with Unity3D projects]]></title>
            <link>https://medium.com/@michalsporna/treasure-hunting-in-video-game-testing-a-tale-about-using-a-test-coverage-tool-with-unity3d-80ca2e434b9a?source=rss-ba49aac0d247------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ca2e434b9a</guid>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[test-coverage]]></category>
            <dc:creator><![CDATA[msporna]]></dc:creator>
            <pubDate>Thu, 09 Aug 2018 22:28:41 GMT</pubDate>
            <atom:updated>2021-11-16T08:19:22.780Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/msporna/LAVA-test-coverage">https://github.com/msporna/LAVA-test-coverage</a></p><h4><strong>Defining Treasure (PROLOGUE)</strong></h4><p>Treasure in QA Engineer’s world is knowledge that allows you to assure quality the best you can. When you have that treasure, you are rich in terms of having a good night sleep without worrying someone finds P1 on production. Sometimes, the knowledge is a well-defined user story with all the acceptance criteria listed and sometimes it’s a tool opening new opportunities. Anyway, as we all already learned from games like Uncharted or Indiana Jones movies, finding treasure requires jumping through quite a number of hoops. It is no different in game testing but fortunately we, the QA, have a bunch of open source projects that we can utilize. Someone already went through those hoops and invented the wheel for us. The wheel that can be mounted in a cart we push towards the light at the end of the tunnel where we meet quality.</p><p>This article is about ‘Lava Test Coverage&#39; open source tool that I created in my free time and as of now am the only maintainer — it supports Unity, Angular and web apps without any framework (pure js). I will be focusing on Unity here. The tool was created to find out what percentage of actual code your testing activity covers. Every feature of a game is tied to some functions in code and all interactions with the game trigger some portions of it. Lava Test Coverage tells you if you covered all of the code, and if not, what exactly was missed. Once you know spots that are not being covered by your test sessions, you can improve and in the end ensure better quality.</p><p>I will be going over on how to get a detailed test coverage report from a test session executed against Unity game (WebGL in my case) and how I improved the following session to cover more portion of the code based on information presented in the coverage report.</p><p>You’ll find relevant links at the bottom of this article.</p><h4>Prepare the expedition (Setup)</h4><p>The first thing to do is to get the Lava Test Coverage tool, so go to your terminal and clone it by running: git clone <a href="https://github.com/msporna/LAVA-test-coverage.">https://github.com/msporna/LAVA-test-coverage.</a> You should get the following set of files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irxkp-pKYdLAyiXTk0sNsg.png" /></figure><p>Highlighted folders are needed in the setup process. Run the latest version of Unity and load the example game from /examples/unity_demo, then copy LavaTestCoverage plugin from repo’s root into unity_demo/Assets/Plugins. The plugin ships with 2 files:<em>LavaHelper.cs</em> and a prefab called <em>LavaTestCoverageGameObject</em>. LavaHelper is responsible for sending usage stats to a backend server that processes them and prepares a report based on that. The prefab, on the other hand, is needed only for triggering Unity’s Awake() and Update() methods — a script must be attached to some game object for those to work. So after the project loads, drop this prefab into the only scene of the project called ‘LAVA’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YuXh1gcT3Jij2u4BXCRiKA.gif" /></figure><p>The LavaHelper plugin exposes SendStats() method. Its call is being automatically injected into every detected .cs source file located in the /Scripts folder of Unity project. That is the next step. It’s called probes injection. This process goes through all automatically detected source files and finds function calls, if &amp; switch statements and other relevant code fragments. It then inserts a probe in there so when original code is executed, called by some action made by a player it rides along, reporting that fact to the backend. Here is an example to make things a bit more clear, some function before injection looks like this:</p><blockquote>public void OnOpen() {</blockquote><blockquote>SetupReferences();</blockquote><blockquote>}</blockquote><p>And after:</p><blockquote>public void OnOpen() { <strong>LavaHelper.SendStats(“BrowserController.cs”,”78ece5a9–0014–433b-93c1-cff7547ea277&quot;,”94&quot;,”function”);</strong></blockquote><blockquote>SetupReferences();</blockquote><blockquote>}</blockquote><p>LavaTestCoverage plugin’s ‘SendStats()’ method requires parameters like filename, unique line guid, line number and injection type. Everything needed to identify executed code line. In the above example line number (94) refers to ‘public void OnOpen() { ’ not to ‘LavaHelper.SendStats()’ — the probe is invisible from the test coverage report point of view. OK, but how to do the injection (or instrumentation)? Simple, it requires running only 1 Python script called ‘instrument_client.py’ located in repo_root/client. However, before the client script can beexecuted, the backend must be running because client script submits detected sources back to it along with few other meaningful information. Run ‘/server/instrument_server.py’ script to serve the backend. This causes 2 things to happen:</p><ol><li>database is created</li><li>Flask app is started serving rest API that instrument_client.py and LavaHelper plugin talk to and frontend (referred to as dashboard) where the report can be viewed</li></ol><p>When that is done, back to client folder edit config.json file by pointing ‘source_root_absolute_path’ to unity demo’s ‘Scripts’ folder and set ‘inject_mode’ to ‘unity’. Last thing to do is to finally run the ‘instrument_client.py’ that</p><ol><li>detects sources located in the Scripts folder</li><li>processes the sources:</li><li>finds code lines that can be injected and inserts probes</li><li>sends contents to the backend to be stored in DB.</li></ol><p>Everything is nicely printed out to the terminal during the process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*_UFwjTuZtz-sqpp7GHm8nA.png" /></figure><p>The script runs for some time (it depends from a number of found sources) and after it is done the game’s source is instrumented (contains LavaHelper.SendStats() lines) and backend is aware of the sources and knows what to expect when stats are being sent to it during testing. Oh yeah, the testing. The game needs to be built in order to proceed to that step so back to Unity project, prepare a build targeting WebGL platform and serve it at localhost:8787 by executing ‘server.py’ script found in examples/unity_demo directory.</p><p>It is time for the fun part: testing the game.</p><h4><strong>Slide down the rope (Testing)</strong></h4><p>The example game is called ‘LAVA SIMULATOR’ and it simulates deploying the LAVA tool along with testing a simple web app, then viewing coverage report. All within the game, by using prepared apps like browser or terminal. The game’s objective is to interact with Lava Test Coverage in Linux-like OS and perhaps teach you how to handle it in a fun way. There are multiple missions and a single one consists of a small piece of overall tool’s documentation telling player to do stuff like open terminal, run instrument_client Python script etc. So it’s the game about the tool that ships with that game used to demonstrate how to use the tool. Damn, I should probably film “Inception 2”. Anyway, I tried to not make it solely click-through experience and added some actual gameplay like for instance in the terminal, where player has to sort command line options in a specific order to be able to execute it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hSdf6wOnYJB9Hzd7ePVyg.gif" /></figure><p>To start gathering stats from the testing activity, a new session must be created in Lava’s dashboard. It can be done either via UI or rest API. I’ll describe it in a more appealing way — which is the frontend way. Head to localhost:5000 to see the dashboard. If everything goes well, you should also see a number of 17 floating next to ‘Modules’ link in the top right corner of the page. The number stands for count of new sources detected during the most recent injection that need to be assigned to some modules. It is worth mentioning that injection can be done countless times (on every master push for example) and the tool supports continuous integration flow. When sources are sent for the first time, they’re stored in DB and from that point, each new injection is compared to the original one. So when next injections happen to have fewer source files, the tool won’t allow selecting those in new sessions but will still present them in archived ones.</p><p>Modules can be anything, those are like categories for the source files. To start a new test session, at least 1 module must be chosen so you need to create a minimum of 1 module containing at least 1 source file. I think it is a good idea to create modules according to available game features. In LAVA_SIMULATOR’s case I have:</p><ol><li>browser — sources related to the in-game browser</li><li>terminal — sources related to the in-game terminal</li><li>main — all of the other sources, because I’m lazy</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sz0xKambsrC78QKZ6gv2GQ.gif" /></figure><p>Once the sources are assigned and modules ready, we can finally head on to creating a new test session. Let’s select all of the modules because we are going to play the game for the first time so we’ll need a good initial feedback on how much of the code is covered and which areas are hiding in the shadows and keep away from our testing eyesight like little Solid Snakes.</p><p>When there is an active test session, the backend is listening for incoming stats! Go ahead, start the LAVA_SIMULATOR game and just play it for a while. Stats will be coming to Lava rest API behind the curtains, it can be noticed in server’s logs or in some proxy tool like Fiddler:</p><blockquote>localhost:5000/send_instrumentation_stats?file=MainController.cs&amp;line_guid_p=df52f803-aa4c-4fa1-ac18–83547820af8c<br>&amp;route=None&amp;related_code_line=48&amp;inject_type=function</blockquote><p>When your test session is done, and you are ready to view the coverage report return to Lava dashboard and stop your test session by clicking on the stop icon located in the last column of the sessions table. Select the session to open the report.</p><h4><strong>Review found goods and estimate how wealthy you became (study the report)</strong></h4><p>The report has a few sections — the overall coverage across all source files, coverage by source file and then coverage by a module. All tables are sortable. I like to sort sources table ascending by percentage to see which one is the least covered one. Then I open it by clicking on a name to see exactly which lines of code were executed (green) and which were not (yellow), meaning the tests need to be improved to fix that. We want to see those yellow lines become green in the following reports.</p><p>In the .gif below I’m reviewing ‘IDEController.cs’ — notice that some items within the switch statement were never executed. This is the code related to displaying text within in-game app, that behaves like notepad or IDE. The switch statement determines which text to show based on which file was clicked by a player that triggered this function showing file content. From the report, I can figure out that when playing the game I never opened files called ‘about’ and ‘index’. This is a hole that needs to be cemented in the next iteration. The treasure is ours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HN7N8ssFW9Mfb8uD0NLyDA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRY_u47Y6zUE7buy6XELYQ.png" /></figure><h4><strong>Return for a missing artifact (improvement)</strong></h4><p>The hardest part in a process of improvement based on information from coverage report is to specifically determine which in-game fragments, related to those missed code lines, were not tested. Developers responsible for that code can surely help or if you know the code you can do it by yourself.</p><p>Once that’s clear and test cases are updated, create a new test session in Lava and start the game again. Now in addition to what was tested before, focus on items that were missed. In this demo case, we know that some lines from ‘IDEcontroller.cs’ were never fired, which means I never clicked on at least 2 items representing files that can be opened to view some text. We want to test if shown text is what it’s expected to be, so going in there is essential part of assuring quality of the game. After the testing, when it comes to reviewing the coverage report we can go straight to IDEController’s executed lines popup again to see if those lines were in fact executed — and yes, the test coverage got improved!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EpFZx-ZgZMLq8Bk1Gh8W8g.gif" /></figure><p>While grinning to that nice green color, notice that the overall coverage percentage of this certain file and across all modules got higher as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqKfekWR704QU7Okha4vdg.png" /></figure><p>You must know that a session diff feature is in my backlog — it will show a nice info on how much each file, module, and overall percentage got improved compared to a previous session. I know it will be useful. Until then, the comparison must be done manually, but from a glance on total coverage value of each session on the main dashboard’s page, it is pretty clear.</p><h4><strong>EPILOGUE</strong></h4><p>Testing games is fun but it can also be a nightmare — with not so many off-the-shelf tools for video game testing out there, QA engineers should try as many available ones as they can to pursuit continuous testing quality improvement. Lava Test Coverage creates such opportunity. By writing this article, besides describing how easy it is to get test coverage, I wanted to express my hopes for someone else using it as well, perhaps giving me some feedback. I wish it to be a really useful tool and have many interesting features on my mind to implement in near future. Unity engine support is just the beginning, it would be awesome to support others. If you are in video game testing and got even remotely interested by it, give it a try — see how it runs with your product and process. Who knows, maybe it will help in increasing your test coverage and happen to add a brick to a great construction called a well-tested game.</p><p>Also, please consider sharing this post to the fellow QA Engineers to spread the word that there is such tool available. The more potential contributors it gets, the better for the community.</p><p>NOTE: the article was written for version 2 of the tool. Recently version 3 was released so you could find slight inconsistencies.</p><h4><strong>RESOURCES</strong></h4><p><strong>LAVA Test Coverage</strong></p><p><a href="https://github.com/msporna/LAVA-test-coverage">https://github.com/msporna/LAVA-test-coverage</a></p><p><strong>Make sure to read wiki to get detailed info on how to set everything up:</strong></p><p><a href="https://github.com/msporna/LAVA-test-coverage/wiki/Setup-for-Unity-game">https://github.com/msporna/LAVA-test-coverage/wiki/Setup-for-Unity-game</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ca2e434b9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>