Cannot access app settings from RunNoEvil unit tests

o A Descriptive Title (i.e. “Simulator Freezes Launching App in Eclipse”)
Cannot access app settings from RunNoEvil unit tests

o The Environment:
Windows 7
Eclipse Neon.2 (4.6.2)
ConnectIQ 2.2.3

o A detailed description of the issue
Calling AppBase.getProperty(), setProperty(), or deleteProperty() functions from a RunNoEvil test will result in an Unexpected Type Error exception.

o Steps to reproduce the issue
Build and run the test code provided as a unit test (build and run with -t).

o Any applicable additional information
It doesn't matter if the property being accessed is a property defined as a resource or not. Testing shows that the app instance returned by App.getApp() is an instance of my class, but it has not been initialized properly.

o A code sample that can reproduce the issue (in email only if preferred)
using Toybox.Application as App;
using Toybox.System as Sys;

(:test) function test_setProperty(logger)
{
App.getApp().setProperty("myNumber", 1);
return true;
}

(:test) function test_getProperty(logger)
{
App.getApp().getProperty("myNumber");
return true;
}

(:test) function test_clearProperties(logger)
{
App.getApp().clearProperties();
return true;
}

(:test) function test_deleteProperty(logger)
{
App.getApp().deleteProperty("myNumber");
return true;
}

(:test) function test_validateProperty(logger)
{
App.getApp().validateProperty("myNumber", 1);
return true;
}

class XApp extends App.AppBase
{
function initialize() {
AppBase.initialize();
}

function getInitialView() {
return null;
}
}


As mentioned, it doesn't matter if a setting or a property is used. Here is the resources/resource.xml that I tested with.

<resources>
<drawables>
<bitmap id="LauncherIcon" filename="bitmaps/launcher_icon.png" />
</drawables>

<strings>
<string id="AppName">X</string>

<string id="myNumberTitle">Title</string>
<string id="myNumberPrompt">Prompt</string>
<string id="myNumberError">Error</string>
</strings>

<layouts />

<properties>
<property id="myNumber" type="number">0</property>
</properties>

<settings>
<setting propertyKey="@Properties.myNumber" title="@Strings.myNumberTitle" prompt="@Strings.myNumberPrompt">
<settingConfig type="numeric" errorMessage="@Strings.myNumberError" />
</setting>
</settings>
</resources>


Here is the output that I get.

File pushed successfully
Connection Finished
Closing shell and port
Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
------------------------------------------------------------------------------
Executing test test_setProperty...
Failed invoking <symbol>
Unexpected Type Error
in test_setProperty (source\XApp.mc:7)
in runTest (UnitTests:37)
ERROR
------------------------------------------------------------------------------
Executing test test_getProperty...
Failed invoking <symbol>
Unexpected Type Error
in test_getProperty (source\XApp.mc:13)
in runTest (UnitTests:44)
ERROR
------------------------------------------------------------------------------
Executing test test_clearProperties...
PASS
------------------------------------------------------------------------------
Executing test test_deleteProperty...
Failed invoking <symbol>
Unexpected Type Error
in deleteProperty (D:\jenkins\workspace\Tech-CIQ-Win-Rel\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\Application.mb:140)
in test_deleteProperty (source\XApp.mc:25)
in runTest (UnitTests:58)
ERROR
------------------------------------------------------------------------------
Executing test test_validateProperty...
PASS

==============================================================================
RESULTS
Test: Status:
test_setProperty ERROR
test_getProperty ERROR
test_clearProperties PASS
test_deleteProperty ERROR
test_validateProperty PASS
Ran 5 tests

FAILED (failures=0, errors=3)
Connection Finished
Closing shell and port


Travis
  • I also noticed this, not so sure it's a bug, the problem is that you can't do an App.getApp() from within the module context.
    I worked around it with passing the applicationProperties from within the main app and creating a setter in my mock.

    using Toybox.Application as App;

    class PacerTestsApp extends App.AppBase {

    function initialize() {
    AppBase.initialize();
    }

    //! Return the initial view of your application here
    function getInitialView() {
    var app = Application.getApp();
    var view = new PacerMock();
    view.setApplicationProperties(app);
    return [view];
    }

    }


    (And if you've got no mock then I suppose you could also initialize a module level variable...)
  • Hey,

    I've got this one tracked. We'll take a look at it.

    -Coleman