<?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 Deepak Chirammel on Medium]]></title>
        <description><![CDATA[Stories by Deepak Chirammel on Medium]]></description>
        <link>https://medium.com/@deepak.chirammel?source=rss-d05dca60b6d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZA8pK9JJc5oouyQc</url>
            <title>Stories by Deepak Chirammel on Medium</title>
            <link>https://medium.com/@deepak.chirammel?source=rss-d05dca60b6d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:30:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepak.chirammel/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[Securing Enterprise XR Integration for Android : Signature Validation]]></title>
            <link>https://medium.com/xrpractices/android-secure-design-secure-coding-signature-validation-137abd85cbac?source=rss-d05dca60b6d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/137abd85cbac</guid>
            <category><![CDATA[emerging-technology]]></category>
            <category><![CDATA[xr]]></category>
            <category><![CDATA[enterprise]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[signature-validation]]></category>
            <dc:creator><![CDATA[Deepak Chirammel]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 08:53:40 GMT</pubDate>
            <atom:updated>2024-05-03T05:57:17.865Z</atom:updated>
            <content:encoded><![CDATA[<h3>Securing Enterprise XR Integration for Android : Signature Validation</h3><p>HorizonOS which is an extended reality operating system for the Meta Quest line of devices is becoming open by Meta to partners like Microsoft, Lenovo etc. HorizonOS which is based on Android ecosystem along with existing OpenXR is shaping open XR ecosystem and the landscape is changing drastically. These open culture helps the XR ecosystem grow as it brings forth lot of integrations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kK0nEJtYBOMBHBPm19Ixiw.png" /></figure><p>In the previous articles we talked about enterprise XR integration</p><p><a href="https://medium.com/xrpractices/user-account-management-in-xr-devices-aae728b98aae">User Account Management in XR</a></p><p>However, this open culture also brings a whole lot of hidden security vulnerabilities and risks along with it. Here we will presenting how to securely interconnect android apps/services, and this can well help in all XR apps for android based devices. Note that 80% or more of XR devices are already android based.</p><p><a href="https://medium.com/xrpractices/the-growing-list-of-xr-devices-f102262e4a58">The Growing List of XR Devices</a></p><h3>Multi-Tier Architecture</h3><p>In Enterprise Android ecosystem, its very common to see multi-tier architectures in which there will be multiple applications say AppA, AppB etc. which binds and communicates to Service Applications though AIDLs. Typically there comes an instance wherein we create multiple connections to the Service APK between those applications. Every now and then, this question popups regarding Security whether the Service communications are secure or not and is it working as intended or not.</p><h3>Security by Signature Validation</h3><p>In this article, we will be discussing on how to add “<strong>Signature Validation</strong>” and thereby ensure that, unwanted or unsecure connections are not permitted to these protected service applications.</p><h3>Native Android App Setup</h3><p><a href="https://github.com/deepakchirammeltw/signature_validation">GitHub - deepakchirammeltw/signature_validation: Signature Validation in Android</a></p><p>In this above github repo (<strong>master</strong> branch) we have 3 folders namely “<strong>AppA</strong>”, “<strong>AppB</strong>” and “<strong>ServiceApp</strong>”. Both <strong>AppA</strong>, <strong>AppB </strong>are signed with respective <strong>Keystore*.jks</strong> keys and binds to the <strong>ServiceApp </strong>and communicates to the AIDL API named <strong>mailGreeting</strong>. Refer the below diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*dUjeD8ez8vQlJodKvbkOoQ.png" /><figcaption>Flow Diagram — AppA, AppB &amp; ServiceApp</figcaption></figure><p>The <strong>AppA </strong>is using the <strong>KeyStoreA.jks, </strong>thus the generated <strong>AppA.apk</strong> has the signature SHA of “<strong>90:42:FA:E9:3D:F9:00:2D:8B:2C:FF:DD:15:C8:8E:01:B5:96:A9:8E</strong>” as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PV1FT0nTA-mZnJzb2k_f_Q.png" /><figcaption>Certificate Info for AppA.apk</figcaption></figure><p>Note: The same key <strong>KeystoreA.jks</strong> is used for signing <strong>ServiceApp </strong>as well.</p><p>Now, the <strong>AppB </strong>is using the <strong>KeyStoreB.jks,</strong> thus the generated AppB.apk has the signature SHA of “<strong>C5:05:5D:81:CC:20:D9:DE:06:FF:55:12:1E:76:3C:18:B3:CA:63:10</strong>” as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnGqdzYutx1FZ3SRFkKhRw.png" /><figcaption>Certificate Info for AppB.apk</figcaption></figure><p>Both the <strong>AppA</strong> and <strong>AppB</strong> connects/binds to the <strong>ServiceApp </strong>and use the AIDL API <strong>mailGreeting </strong>to show a Snackbar message received from the service as highlighted in Red below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*PTvVO-jpdpCG0Lo61hrVNw.png" /><figcaption>On Pressing the Mail Button, it connects to the Service API mailGreeting and shows the Snackbar.</figcaption></figure><h3><strong>Securing the Services</strong></h3><p>In the above code setup, there is no restrictions at the service end and thus any apps can connect to the service AIDL APIs. For securing the Service APIs, we will need to introduce Signature Validation which validates all incoming connecting requests to the service side and only allows those connection requests which are having the same Signature. This can be achieved by below approaches:</p><h3>1. Custom Permissions with same Signature Level</h3><p>In this approach, we are generating a custom permission say “<strong><em>com.tw.test.service.SERVICE_APP_ACCESS</em></strong>” which is having a <strong><em>protectionLevel</em></strong> of <strong><em>Signature </em></strong>as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ilb0ch7i6PeUfV6lZ7T17w.png" /><figcaption>Custom Permission with Signature Level protection</figcaption></figure><p>The above changes ensure that the any access to this Service requires a particular permission and this particular permission can be only used by apps which has the same signature.</p><p>At the incoming app level <strong>AppA</strong>, there should be the permission usage declared in the manifest as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnbSDg9-7rXllZJiQPvISQ.png" /><figcaption>Usage of permission at “AppA”</figcaption></figure><p>After introducing this custom permission with signature level protection, we could see that the <strong>AppA </strong>which has the same signature as that of <strong>ServiceApp </strong>and works fine as expected.</p><p>However, for <strong>AppB </strong>which has a different signature than <strong>ServiceApp</strong>, we could see that the <strong>AppB </strong>fails to connect/bind and a security exception is thrown while trying to bind as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VNj1rmeeNYkiH3gMq0Vt5w.png" /><figcaption><strong>SecurityException </strong>thrown at “<strong>AppB</strong>” while trying to bind to “<strong>ServiceApp</strong>”</figcaption></figure><p>Please refer branch “<strong>permissions_check</strong>” for the complete code changes. Commit : <a href="https://github.com/deepakchirammeltw/signature_validation/commit/eb66f556f43d5f1b0712716cfdd72730c7e85431">https://github.com/deepakchirammeltw/signature_validation/commit/eb66f556f43d5f1b0712716cfdd72730c7e85431</a></p><h3>2. SHA Validation for incoming Caller Packages</h3><p>In this approach the changes are only done at the Service side and no changes required at the Caller side. All the incoming bind connections from both “<strong>AppA</strong>” and “<strong>AppB</strong>” to the “<strong>ServiceApp</strong>” will be successful, however the AIDL APIs will validate the caller SHA and throw Security Exception whenever it does not meet the required Certificate Fingerprint.</p><p>Here we have specified the valid <strong>SIGNATURE_SHA </strong>to be that of the <strong>AppA </strong>which has <strong>KeystoreA.jks</strong> fingerprint as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eUBTLFtgbaFKYzSGR6RLig.png" /><figcaption>“SIGNATURE_SHA” is to set as “KeystoreA.jks” fingerprint</figcaption></figure><p>As a result the <strong>AppA</strong> binding works fine and the AIDL APIs returns the valid values. But in case of <strong>AppB</strong>, it throws a Security Exception as the AppB is signed with a different signature and thereby not matching the expected SHA/fingerprint as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*siy8Vd6cOPOvey1dfDGJaw.png" /><figcaption>Validation of Signature SHA is done at the AIDL API level and throws Security Exception in case of mismatches</figcaption></figure><p>For the entire code changes, refer branch — “<strong>sha_fingerprint_check</strong>”</p><p><strong>Commit :</strong> <a href="https://github.com/deepakchirammeltw/signature_validation/commit/ca67f7c21d4cf5fbdb705de68989db54a4d9f993">https://github.com/deepakchirammeltw/signature_validation/commit/ca67f7c21d4cf5fbdb705de68989db54a4d9f993</a></p><h3>Comparison</h3><p>Both approaches of Signature Validation has its own advantages and disadvantages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cDc5YQnbylqXwWX7BMjozg.png" /><figcaption>Comparison of approaches</figcaption></figure><h3>Conclusion</h3><p>Open ecosystem for XR is the need of time, but not at the cost of security, having controll mechanism on who can communicate with your apps when exposing to external world is important. Over exposing things would cause more harm and exploitation. This is just basics steps … more in future…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=137abd85cbac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xrpractices/android-secure-design-secure-coding-signature-validation-137abd85cbac">Securing Enterprise XR Integration for Android : Signature Validation</a> was originally published in <a href="https://medium.com/xrpractices">XRPractices</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Refactoring 101: Convert a Service APK to a Library AAR]]></title>
            <link>https://medium.com/xrpractices/android-refactoring-101-convert-a-service-apk-to-a-library-aar-ae946ae88e92?source=rss-d05dca60b6d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae946ae88e92</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[plugins]]></category>
            <dc:creator><![CDATA[Deepak Chirammel]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 03:15:52 GMT</pubDate>
            <atom:updated>2023-01-03T14:33:13.844Z</atom:updated>
            <content:encoded><![CDATA[<p>XR apps generally need native components from underlying OS when the desired functionality can not be achieved by typical XR development tools such as Unity and Unreal or we want to reuse functionality from an existing native app. We also come across a need to to use existing functionality from an existing application/service to be used within XR app built in Unity. <a href="https://medium.com/u/52ee65ca0b8b">Kuldeep Singh</a> and <a href="https://medium.com/u/6b8d20e9607d">Raju K</a> have talked about interoperability in earlier articles: <a href="http://Enterprise XR — Interoperability">Enterprise XR — Interoperability</a> and <a href="https://medium.com/xrpractices/embedding-unity-app-inside-native-android-application-c7b82245f8af">Embedding Unity App inside Native Android application</a>. Here I am sharing way to convert an existing app to a a library and then use it in another andorid app.</p><p>In Android ecosystem, its very common to see multi-tier architectures in which there will be multiple applications say App-A, App-B etc. which binds and communicates with each other though service AIDLs. Typically there comes an instance wherein we create multiple Service APK which acts like a Bridge to communicate between those applications.</p><p>Due to ever growing applications list, there comes a situation that we have many such service APKs and as a best practice, we want to merge those multiple Service APKs into a single combined Service APK. By doing so we avoid installations of multiple individual service APKs and only needs to deal with the install of the single combined service APK.</p><p>At this moment the real question is how to convert a Service APK to an Android library AAR? Does it take a lot of refactoring and time? Do we have to build the library from scratch?<br>Simple Answer: No. It takes hardly 5 mins to convert a service APK to a lib.</p><h3>Code Setup</h3><p>To understand it clearly, lets have a simple setup of an Android Application named “<strong>GreetApplication</strong>” that binds to another Service called “<strong>helloService</strong>”. The entire codebase and the generated APKs are available (<strong><em>greet-application.apk</em></strong> &amp; <strong><em>hello-service.apk</em></strong>) in the github — <a href="https://github.com/deepakchirammeltw/hello">https://github.com/deepakchirammeltw/hello</a> that contains the mentioned folders and generated APKs. On launching the <strong>Greet-Application</strong> it renders a simple 3 button layout and also binds to the <strong>Hello-Service</strong> using “<strong>IHelloService.aidl</strong>” as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YTkMA0uqAKwa5WCXOpLHTQ.jpeg" /><figcaption>GreetApplication Binded to HelloService via IHelloService.aidl</figcaption></figure><p>Note: If you press any of the buttons like “HELLO”, “PING”, and “BYE” from the GreetApplication, it invokes the respective functions of the Service via AIDL which then returns message from the Service accordingly. This returned string messages are displayed as Toast Notifications in the base app.</p><p>Now, back to the original problem — How to convert this HelloService APK to an Android Library AAR say “hello-service.aar” ?</p><h3>Solution</h3><p>Open the <strong><em>build.gradle</em></strong> file for the Hello Service app codebase in Android Studio. There we can see that the plugins that we are using is ‘<strong><em>com.android.application</em></strong>’ and similarly in the ‘<strong><em>defaultConfig</em></strong>’, it has an ‘<strong><em>applicationId</em></strong>’ attribute as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RoQ2odrAvPoH0lD_SWEf9Q.jpeg" /><figcaption>HelloService APK generated since application plugin is used</figcaption></figure><p>To change it to a Android library AAR, the ‘<strong>application</strong>’ plugin used above needs to be replaced with a ‘<strong>library</strong>’ plugin. Similarly, library does not have an ‘<strong>applicationId</strong>’, so it should be also removed from the ‘<strong>defaultConfig</strong>’ as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RNJXhGrjKasZrvdznjn5_w.jpeg" /><figcaption>Hello Service AAR library generated</figcaption></figure><p>Do a gradle sync after making changes to the <strong><em>build.gradle</em></strong> file and then do clean build which generates the Hello-Service Library AAR as shown above.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae946ae88e92" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xrpractices/android-refactoring-101-convert-a-service-apk-to-a-library-aar-ae946ae88e92">Android Refactoring 101: Convert a Service APK to a Library AAR</a> was originally published in <a href="https://medium.com/xrpractices">XRPractices</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jasmine: JS Testing Framework — Part 2/3]]></title>
            <link>https://medium.com/@deepak.chirammel/jasmine-js-testing-framework-part-2-3-5b9ed067af5b?source=rss-d05dca60b6d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b9ed067af5b</guid>
            <category><![CDATA[practice]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[jasmine]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Deepak Chirammel]]></dc:creator>
            <pubDate>Wed, 19 Aug 2020 17:21:21 GMT</pubDate>
            <atom:updated>2020-08-19T17:38:34.556Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jasmine: JS Testing Framework — Part 2/3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*fMu9GilusJyiWJIUo4alLQ.png" /><figcaption>BDD framework for testing JS</figcaption></figure><h3>Jasmine Framework</h3><p>In the previous post, we discussed about various JS testing frameworks and what factors are to be considered while choosing a framework.</p><p><a href="https://medium.com/@deepak.chirammel/choosing-a-js-testing-framework-in-xr-part-1-3-385c57fd7d94">Choosing a JS Testing framework in XR — Part 1/3</a></p><p>In this article, we will cover the following:</p><ol><li>How to setup and run the Jasmine tests as part of your code-base.</li><li>Fundamentals and basics of writing JS Specs using Jasmine.</li></ol><p><em>Note: JS unit tests are also known as Specs.</em></p><h3>Jasmine Setup</h3><p>Setting up Jasmine as a standalone module as part of the code repository is pretty straightforward.</p><ol><li>Head to the Jasmine <a href="https://github.com/jasmine/jasmine/releases">releases</a> page in GitHub and take the latest standalone release (which is 3.5.0). It already contains some sample tests.</li><li>Open the <strong>SpecRunner.html</strong> file in a browser of choice to run the JS Specs/tests</li><li>Create similar Spec files for testing your code base and refer them in the <strong>SpecRunner.html</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZpY6xdATkAkIhqmx-KLEeg.png" /><figcaption>SpecRunner</figcaption></figure><p>That’s it. You have successfully added the Jasmine framework to your code base. Now your team can use it to do TDD for development and simply run the <strong>SpecRunner.html</strong> to execute JS tests. 👏👏👏</p><h3>describe-it</h3><p>The ‘<strong>describe</strong>’ and ‘<strong>it</strong>’ are the fundamental keywords for writing JS specs. The first parameter is the string value to describe what the test is doing . The second parameter is a function (callback) where the actual functionality is being tested. Even nested <strong>describe’s</strong> are supported for consolidating and organizing tests. Jasmine also supports <strong><em>beforeEach</em></strong>, <strong><em>afterEach</em></strong>, <strong><em>beforeAll </em></strong>and <strong><em>afterAll </em></strong>blocks which are useful for extracting the common setup and tear-down codes which need to be executed for each of these tests as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJeI9c9o82bUbPO5J4e1XA.png" /><figcaption>A sample Spec format using describe/it in Jasmine</figcaption></figure><h3>Assertion using “expect” matchers</h3><p>Assertion or verifying whether the given unit is working as expected is done by using the ‘expect’ assertions. Jasmine already provides enough built-in matchers out of the box as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xgRztWZ3oTpjL1GUriqdIg.png" /><figcaption>Built-In Matchers</figcaption></figure><p>Apart from the built-in matchers, there is provision to create your own custom matcher by using the <strong>addMatchers </strong>function<strong> </strong>as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*_aHe3OXN7znUuKYIKHE8LA.png" /><figcaption>Adding Custom Matchers using the <strong>addMatchers()</strong></figcaption></figure><h3>Mocking using Spies</h3><p>Mocking is the process used in unit testing when the unit being tested has external dependencies. The purpose of mocking is to isolate and focus on the code being tested, and not on the behavior or state of external dependencies. In Jasmine, mocking is done using <strong>Spy </strong>as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*dQ06Dch38QV5g2AFZP_DZQ.png" /><figcaption>Creating Spies in Jasmine</figcaption></figure><p><strong><em>Note:</em></strong><em> Mocking is less preferred because it can lead to over-specification of tests. This overuse of mocks can lead to some tests that don’t really test anything. A better approach is to always go with </em><strong><em>stub</em></strong><em> if possible so as to avoid mocking.</em></p><h3>SpyOn and Stubs</h3><p><strong>Spyon </strong>is the most widely used mock approach in Jasmine. It already has several <strong>stubs</strong> supported out of the box like “<strong>and.returnValue</strong>”, “<strong>and.callFake</strong>”, “<strong>and.callThrough</strong>” etc as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VBziElUem1QgqhbFoZxyoQ.png" /><figcaption>SpyOn and Stubs</figcaption></figure><h3>Spy Matchers</h3><p>Jasmine also has several spy matchers out of the box which can be used to assert whether the spied on matcher is working as expected. As suggested earlier, you can also create your own custom matchers if needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFnUD83PidlCsso1MVW5QQ.png" /></figure><h3>Asynchronous Testing</h3><p>During development there will be several occasions where we will be having asynchronous functionalities like <strong>setTimeouts</strong>, <strong>Promises</strong>, <strong>AJAX network calls</strong> etc. For testing these asynchronous units, Jasmine expects a <strong>done </strong>callback to be invoked after the test is executed — usually by a finally block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4nweF89blmc8_HeMAIwAA.png" /><figcaption>Async Tests needs to invoke the done callback after execution</figcaption></figure><h3>Conclusion</h3><p>In this article we discussed in detail on setting up the Jasmine Test framework as part of your project code-base and running the Specs locally using the SpecRunner. We also learned the basics of writing a Jasmine spec, understanding on the assertion and mocking libraries (<em>which comes out of the box with Jasmine framework</em>).</p><p>In the next article, we will be covering about running these specs as part of the CI. We will also learn how to set-up a production-like-test environment using tools like <a href="https://karma-runner.github.io/latest/index.html">Karma</a> and <a href="https://istanbul.js.org/">Istanbul</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b9ed067af5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing a JS Testing framework in XR — Part 1/3]]></title>
            <link>https://medium.com/xrpractices/choosing-a-js-testing-framework-in-xr-part-1-3-385c57fd7d94?source=rss-d05dca60b6d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/385c57fd7d94</guid>
            <category><![CDATA[practice]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[webxr]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Deepak Chirammel]]></dc:creator>
            <pubDate>Wed, 19 Aug 2020 11:43:18 GMT</pubDate>
            <atom:updated>2020-08-20T05:57:11.898Z</atom:updated>
            <content:encoded><![CDATA[<h3>Choosing a JS Testing framework in XR — Part 1/3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*G3duWaNxbEXhCfJxVLk0fw.png" /><figcaption>JS Everywhere</figcaption></figure><h3>JS Everywhere!</h3><p>More than 95% of web-applications today use JavaScript as its client-side programming language. The introduction of <a href="https://nodejs.org/">NodeJS</a> has brought about a revolution in server-based technology. It is the reason why more JavaScript-based frameworks are getting popular among the developer community — thanks to Google Chrome Team for open-sourcing V8 JavaScript engine!</p><p>By the <a href="https://www.w3.org/DesignIssues/Principles.html">principle of least power</a>, JavaScript has become the <em>de facto</em> language of the web. Even in AR-VR space, JavaScript is gaining popularity and is widely used in segments like <a href="https://www.w3.org/TR/webxr/">WebXR</a>. The famous quote of <a href="https://en.wikipedia.org/wiki/Jeff_Atwood">Jeff Atwood</a> — Co-founder of StackOverflow — about JavaScript back in 2007 is fast becoming a reality now:</p><blockquote>“Any application that can be written in JavaScript, will eventually be written in JavaScript.” — Atwood’s Law</blockquote><h3>JS Testing Frameworks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lWr_xXEFIFjjhBeR4lNZAg.png" /><figcaption>stateofjs.com testing 2019</figcaption></figure><p>According to <a href="https://2019.stateofjs.com/testing/">stateofjs.com</a>, amongst many JS testing frameworks available in the market, <a href="https://jestjs.io/">Jest</a>, maintained by Facebook, is the most favorite among developers. With the rising popularity of <a href="https://reactjs.org/">ReactJS </a>and other front-end frameworks like <a href="https://vuejs.org/">VueJS</a>, preference for Jest has also gone up in recent times.</p><p>While the earliest testing frameworks have been around for more than a decade, few new ones have evolved by leveraging the earlier frameworks. Jest is built on top of the <a href="https://jasmine.github.io/">Jasmine</a> framework with a focus on simplicity and so far has lived up to its expectations with the advent of zero-config based setup (work out of the box, config free).</p><p><a href="https://jasmine.github.io/">Jasmine</a> is a BDD styled, standalone, independent framework (need not even have a DOM) which is ideal for TDD. It has a clean, obvious syntax so that one may easily get started with writing tests. It is widely adopted as the testing framework in <a href="https://angularjs.org/">AngularJS</a> and is usually the first choice to be used along with <a href="https://karma-runner.github.io/latest/index.html">Karma</a> (<em>a command-line based spec runner tool for running Jasmine Specs aka tests in a production-like test environment</em>). Jasmine also has a decent built-in assertion library (<em>expect</em>) and a mocking library (<em>spy</em>) out of the box.</p><p><a href="https://mochajs.org/">Mocha</a> is a significantly more flexible framework, but one has to piece it together — both mocking and assertion libraries are missing within the framework by default. As a mocking library, <a href="https://sinonjs.org/">sinon.js</a> (<em>the ultimate spy library</em>) is usually configured. Similarly, for the assertion, <a href="https://www.chaijs.com/">chai</a> or <a href="https://github.com/Automattic/expect.js">expect.js</a> is widely used. Thanks to its flexibility in using configurable assertion and mocking libraries, mocha is the most preferred JS test framework in the developer community.</p><h3>Choosing a JS Test Framework</h3><p>Recently I was developing a browser-based AR android application. It started as a simple URL based streaming application: but in due course, it had more feature requests coming in like <em>Login</em>, <em>Screenshot</em>, <em>Recording, Pause</em>/<em>Resume </em>&amp; <em>Start</em>/<em>Stop image stream, </em>etc. Instead of using any front-end frameworks like <em>ReactJS </em>or <em>VueJs,</em> we used plain vanilla JavaScript — even no node based modules — as it served our purpose (<em>we</em> <em>only had to invoke simple API end-points using AJAX</em>).</p><p>The need of the hour was to set-up a JS testing framework to develop on the additional features. At the time, our team mostly consisted of Android and Unity developers and was fairly new to the ways of JS and its testing methodologies.</p><p><strong>Jasmine</strong>, <strong>Jest, </strong>and <strong>Mocha </strong>were shortlisted initially — of which <strong>Jasmine </strong>was selected 👊 due to the following reasons:</p><ol><li>Since the team was fairly new to JS, we needed a framework which was easy to learn for beginners</li><li>We also ensured that adequate documentation and examples were available online for reference.</li><li>We wanted an easy to setup framework, with less moving parts (we <em>preferred having both </em><strong><em>mocking </em></strong><em>and </em><strong><em>assertion </em></strong><em>libraries within the framework — out of the box by default</em>).</li><li>As we were using plain vanilla JS and not any front-end frameworks, we required a test framework that was standalone and could run the tests immediately — thus providing faster feedback for developers, to write and run tests during development.</li><li>The tests had to be executed as part of our CI pipeline — with Bamboo as our CI and JFrog as the artifactory.</li></ol><p>What we also learned during the development cycle is that, its:</p><ol><li>Good to have, if the JS tests can be run from IDE itself (<em>this was going to be challenging, given that the IDE used in our project was Android Studio </em>😣).</li><li>Better to have JS coverage reports generated too, as part of the CI.</li></ol><p>Apart from all the above points, earlier familiarity with any of the given test frameworks also helps in choosing the right test framework.</p><p>After a short knowledge sharing session with our team on getting started with Jasmine, we found the framework quite easy and straightforward. There will be JavaScript experts from our AR-VR team soon 👊. Below is the screenshot of the JS test coverage on the completion of our project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KeAB8zQHrnGvfWwc_TbrCg.jpeg" /><figcaption>JS Test Code Coverage</figcaption></figure><p>This is what “<strong>Developers call it Done”</strong>. 👏👏👏</p><h3>Conclusion</h3><p>There are several JS test frameworks available in the market. Choosing the right framework depends on a multitude of factors. For our project, we chose Jasmine as the JS test framework based on the requirements articulated above.</p><p>In the next part of the <a href="https://medium.com/@deepak.chirammel/jasmine-js-testing-framework-part-2-3-5b9ed067af5b">article</a>, we will explain in-depth how to set up Jasmine as part of a project code-base, fundamentals on how to write specs, and lastly running them as part of CI, with test-coverage reports.</p><p><a href="https://medium.com/@deepak.chirammel/jasmine-js-testing-framework-part-2-3-5b9ed067af5b">Jasmine: JS Testing Framework — Part 2/3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=385c57fd7d94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xrpractices/choosing-a-js-testing-framework-in-xr-part-1-3-385c57fd7d94">Choosing a JS Testing framework in XR — Part 1/3</a> was originally published in <a href="https://medium.com/xrpractices">XRPractices</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Practical PlayMode Testing in Unity3D]]></title>
            <link>https://medium.com/xrpractices/practical-playmode-testing-in-unity3d-5ea455bf28b0?source=rss-d05dca60b6d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ea455bf28b0</guid>
            <category><![CDATA[practice]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[testing-framework]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Deepak Chirammel]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 18:18:22 GMT</pubDate>
            <atom:updated>2020-06-22T10:01:06.778Z</atom:updated>
            <content:encoded><![CDATA[<p>Automation Tests are an integral part of the Software Development Life Cycle (SDLC). The Unity Test Framework (UTF) enables Unity Users to test their code in both <strong>EditMode</strong> and <strong>PlayMode</strong>. The UTF can be run in different target platforms such as Stand-Alone (i.e., from Unity Editor itself), Android, iOS, etc.</p><p>The basic setup of the Unity Test Framework, Mocks, Edit Mode Tests, etc, are covered in the earlier article from <a href="https://medium.com/u/52ee65ca0b8b">Kuldeep Singh</a></p><p><a href="https://medium.com/xrpractices/practical-unit-testing-in-unity3d-f8d5f777c5db">Practical Unit Testing in Unity3D</a></p><p>Here we will be covering more on the end-to-end integration side of testing in Unity using <strong>PlayMode</strong> Tests.</p><h3><strong>LetsPlay Project Setup</strong></h3><p>This project is an extension of <a href="https://github.com/thinkuldeep/ShowMeTDD"><strong><em>ShowMeTDD</em></strong></a> wherein we create a simple application to sum two given numbers and automatically calculate the result.</p><p>Refer to the <a href="https://github.com/DeepakChirammel/LetsPlay/commit/41df0f0f0e269b58d3196af870cad52fff58d529"><em>commit hash</em></a> from the project <a href="https://github.com/DeepakChirammel/LetsPlay"><strong>LetsPlay</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LirDirD2R7Rfx3PbZSe4jg.jpeg" /><figcaption>On Entering values for A and B, it automatically calculates the <strong>Sum</strong>.</figcaption></figure><p>Any application build in Unity on running will be generating frames in a continuous succession one after the other. This is popularly known as FPS or Frames per second. The FPS for any unity application can be configured by modifying the <a href="https://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html"><strong><em>Application.targetFrameRate</em></strong></a> property.</p><p>Unity provides several in-built functions called <a href="https://docs.unity3d.com/Manual/EventFunctions.html"><strong>Event functions</strong></a><strong> </strong>like <em>Start</em>, <em>Update</em>, <em>Destroy,</em> etc. These event functions have specific <a href="https://docs.unity3d.com/Manual/ExecutionOrder.html">order/sequence</a> of execution which can be extended and used for achieving certain desired goals.</p><p>For our use case, in order to calculate the sum of two numbers <em>(</em><strong><em>A</em></strong><em> and </em><strong><em>B</em></strong><em>)</em> automatically we will be using the <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html"><strong><em>Update</em></strong></a> event function as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWf8mCnGd2DK0SWYTmzaUg.jpeg" /><figcaption>Update event gets fired on every Frame which in-turn calculates the sum</figcaption></figure><p><strong><em>PS:</em></strong><em> This </em><strong><em>Update </em></strong><em>event function is called on every frame. So it&#39;s imperative that it should be used judiciously. No CPU intensive or time-consuming code should be used here as it can drastically affect the FPS and make the application slow/crash on different CPU machines or platforms. As a best practice, it&#39;s even better to create a </em><strong><em>coroutine </em></strong><em>(which are like separate threads) and delegate the script action to the </em><strong><em>coroutine</em></strong><em>, so as to free/leave the Main UI thread alone.</em></p><p>Now back to the project, when we run the <strong>LetsPlay </strong>scene and on entering the values for <strong>A</strong> and <strong>B</strong>, the resultant <strong>sum </strong>is calculated immediately as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvXPCPANfVhV39keto5YNw.jpeg" /><figcaption>The resultant sum is calculated instantly</figcaption></figure><p>So far we have been doing excellent TDD which covers the individual Unit/Blocks and it covers the tests. Here comes the next challenge: <br>-&gt; <strong><em>How do you write an end-to-end test for the given scenario? <br></em></strong><em>-&gt;</em><strong><em> How to test Update event which gets fired only on running?</em></strong></p><h3><strong>Play Mode Tests</strong></h3><p><strong>PlayMode </strong>Tests allow you to exercise the actual app/game simulation in real and verify that it runs as desired. Let&#39;s create <strong>PlayMode </strong>tests as shown below:</p><ol><li>Select the <strong>PlayMode</strong> Tab from the <strong>Test Runner </strong>and create a test assembly folder for the <strong>PlayMode </strong>Tests.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QU_ZDpnkj6eA_DW6xgTz0Q.jpeg" /><figcaption>Creating PlayMode Test Assembly Folder</figcaption></figure><p>2. Now create a Test class named “<strong>LetsPlayTests</strong>” as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smjIr1xkpSrvW-F_izIbow.jpeg" /><figcaption>Default Blank <strong>PlayMode </strong>Test class</figcaption></figure><p><em>PS: For the creation of the end-to-end scenario </em><strong><em>PlayMode </em></strong><em>test, we will be using the </em><strong><em>UnityTest </em></strong><em>annotation (so that it runs as a coroutine). Before running, we also need to set up and load the actual scene named “</em><strong><em>LetsPlay”</em></strong><em>.</em></p><p>3. Let&#39;s load the Scene <strong><em>LetsPlay</em></strong> and write a decent end-to-end <strong>PlayMode </strong>Test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QaB9-sQ24-z00gh18Dg5cw.jpeg" /><figcaption>Input values for <strong>A</strong> and <strong>B</strong>, Give back the thread control via “yield return null” which calls <strong><em>Update</em></strong> Event</figcaption></figure><p>As shown in the above image, we are loading the scene as an <strong><em>OneTimeSetUp</em></strong>. And in the <strong><em>UnityTest</em></strong>, we assign values for the Input Fields <strong>A</strong> and <strong>B</strong>, then exits out the current thread via “<strong><em>yield return null</em></strong>”. This in turn will call the <strong><em>Update</em></strong> Event as per the next order/sequence of execution. Thus the <strong><em>sum </em></strong>result calculation step in the <strong><em>Update </em></strong>event gets executed which later is getting asserted/verified in the <strong><em>PlayMode </em></strong>Test.</p><p><strong>Note:</strong> The complete source code is available in <a href="https://github.com/DeepakChirammel/LetsPlay"><strong>GitHub</strong></a>.</p><h3><strong>General Tips/Tricks for PlayMode Tests</strong></h3><ol><li>On running the <strong><em>PlayMode </em></strong>Tests for the very first time, we might face an issue saying “<em>Scene couldn’t be loaded because it has not been added to the build settings or the AssetBundle</em>”.<br>To fix it, from the menu, open <strong><em>File-&gt;Build Settings, </em></strong>and <strong><em>Add the Open Scene</em></strong>.</li><li>Loading the Scene might be time-consuming sometimes<em>(in case of heavy computations/bigger scenes/large number of gameObjects in the scene/platform or CPU limitations etc)</em>. So accordingly add a <strong><em>WaitForSeconds</em></strong> before executing your tests, so that it waits to completely load the scene correctly.</li><li>There are several functions that can be used inside a <strong>coroutine</strong> such as <strong><em>WaitForEndOfFrame</em></strong>, <strong><em>WaitUntil, WaitWhile, WaitForFixedUpdate, </em></strong>etc which can easily test Unity <strong><em>Event</em></strong> functions. Most of the time, these automated tests will be running as part of some <strong>CI</strong> via a command line <em>(i.e., non-graphical way in which the </em><strong><em>Unity Editor</em></strong><em> is not opened at all)</em>. So in those cases, certain features like <strong><em>WaitForEndOfFrame </em></strong>are not supported <em>(no UI means no frames generated)</em>. So it&#39;s better to go for decent/safer time delays by using <strong><em>WaitForSeconds </em></strong>for supporting different platforms in the <strong><em>PlayMode</em></strong> Tests.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ea455bf28b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xrpractices/practical-playmode-testing-in-unity3d-5ea455bf28b0">Practical PlayMode Testing in Unity3D</a> was originally published in <a href="https://medium.com/xrpractices">XRPractices</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>