<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://forums.garmin.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Unit test example &amp;amp; how to run it</title><link>https://forums.garmin.com/developer/connect-iq/f/discussion/319988/unit-test-example-how-to-run-it</link><description>Where can I find an example unit test code that can be run? And how? I wrote a test class, but I think I misunderstand something in the documentation, because when I try to compile and run it (VSC: Monkey C: Run Tests) I get these errors: 
 java -Xms1g</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 08 Jan 2023 08:49:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://forums.garmin.com/developer/connect-iq/f/discussion/319988/unit-test-example-how-to-run-it" /><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1552298?ContentTypeID=1</link><pubDate>Sun, 08 Jan 2023 08:49:38 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:11a87407-c125-4a74-b12f-09995a95f6e5</guid><dc:creator>flocsy&amp;#129312;</dc:creator><description>&lt;p&gt;Hehe, I&amp;#39;ll add it to my TODO list right after: write a code-generator that parses the devices xmls and generates source files with constants and monkey.jungle file is a useflul way :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1552256?ContentTypeID=1</link><pubDate>Sun, 08 Jan 2023 04:03:28 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:df98bc07-2f2e-4f72-a6c7-7d8cb5dab14a</guid><dc:creator>flowstate</dc:creator><description>&lt;p&gt;Write a code generator that creates 256 test functions /s&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1552185?ContentTypeID=1</link><pubDate>Sat, 07 Jan 2023 21:58:54 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:cb7c6284-e8d3-48b9-9569-41892ecffd3b</guid><dc:creator>flocsy&amp;#129312;</dc:creator><description>&lt;p&gt;Yes, but I don&amp;#39;t see how that&amp;#39;s related. I already use mocks (not in the conventional way though), but what I was looking for is how to have 256 tests instead of 1. Currently I have 1 test that loops over the numbers 0..255 and fails at the 1st one that fails the function I test, but I&amp;#39;d like to see all the numbers when it fails. In another language this would looks something like:&lt;br /&gt;&lt;br /&gt;(:dataProvider)&lt;br /&gt;function dataProvider() as Array&amp;lt;Number&amp;gt; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; return [0,1,2,3,...255];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;(:testWithDataProvider(:dataProvider))&lt;br /&gt;function test(hr as Number) as Boolean {&lt;br /&gt;&amp;nbsp; // use hr&lt;br /&gt;&amp;nbsp; return true or false;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;so test would be called with each value, and I would see each of the failing values in one run.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1551408?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 14:00:35 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:ee65725c-2080-4216-8e52-864d7a1d8a89</guid><dc:creator>peterdedecker</dc:creator><description>[quote userid="187638" url="~/developer/connect-iq/f/discussion/319988/unit-test-example-how-to-run-it/1551332#1551332"]Anyone has a trick for data providers? ;)[/quote]
&lt;p&gt;did you read the tutorial? it has a whole section about mocking ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1551373?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 12:54:01 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:7fab0051-a65f-4b4f-ad8a-d7e59fcec8e7</guid><dc:creator>flowstate</dc:creator><description>&lt;p&gt;Yeah, I&amp;#39;m the last to claim that anything in Monkey C makes sense to me. &amp;macr;\_(ツ)_/&amp;macr;&lt;/p&gt;
&lt;p&gt;Glad it&amp;#39;s working for you now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1551332?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 11:23:53 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:c79ca9c6-c859-4218-9494-50d903bd5590</guid><dc:creator>flocsy&amp;#129312;</dc:creator><description>&lt;p&gt;It would&amp;#39;ve make more sense to have the test function next to the private function I wanted to test, and according to the docs it should have worked if they are static. But I copied it to global and now it works.&lt;/p&gt;
&lt;p&gt;I have one problem though:&lt;/p&gt;
&lt;p&gt;Anyone has a trick for data providers? ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1551247?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 07:34:37 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:9f122349-222b-4da4-9a44-5928c97dea21</guid><dc:creator>peterdedecker</dc:creator><description>&lt;p&gt;I have a whole tutorial on my website on how I set up unit tests, the tutorial talks about eclipse, but the concept still stands in vs code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://starttorun.info/garmin-connect-iq-tutorial-overview/"&gt;starttorun.info/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;tutorials 4-6 apply, read them in order. &lt;span class="emoticon" data-url="https://forums.garmin.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unit test example &amp; how to run it</title><link>https://forums.garmin.com/thread/1551205?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 02:34:19 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:528f5ce4-7cbf-4bec-b768-caada3bb9b00</guid><dc:creator>flowstate</dc:creator><description>&lt;p&gt;Not sure why you&amp;#39;re getting that type error, but you don&amp;#39;t want to define a test class, you want to define (global) test functions:&lt;/p&gt;
&lt;p&gt;This works fine for me:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;import Toybox.Test;

(:test) function testFoo(logger as Logger) {
    logger.warning(&amp;quot;warning&amp;quot;);
    logger.debug(&amp;quot;debug&amp;quot;);
    logger.error(&amp;quot;error&amp;quot;);
    return 42 == 42;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;------------------------------------------------------------------------------
Executing test testFoo...
WARNING (21:33): warning
DEBUG (21:33): debug
ERROR (21:33): error
PASS

==============================================================================
RESULTS
Test:                                Status:
testFoo                              PASS
Ran 1 test

PASSED (passed=1, failed=0, errors=0)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>