how to detect I'm *not* running in the simulator

Former Member
Former Member
I have properties that I set to different values in order to tell the watchface to mock certain things.
I'm looking for some API or property that helps me check if I'm running on real watch and automatically switch off all mocks and test/debug code.

I noted by accident there is App.getApp ().getProperty ("testMode") that's always true in the simulator. Is that set to false when on device?

Overall, the test framework is pretty useless for me because I can't use the App, can't run UI and that's the more challenging code I'd like to test. Don't have many functions I'd like to unit test. I need much more something that gives me experience comparable to the way Selenium is used to test mobile and web UIs.
  • There have been a few tricks for sim/not sim over time, but nothing std that might not go away in the next SDK ("testMode" could be like that even if it works today).

    I go simple and have a global boolean "isSim" if I need it, and if it's not doing something obvious, have an indicator I show on the display so if I sideload a version with it set, it's easy to catch.

    You could also use the Object Store and have a property there you can change in the sim (not in The App App Settings Editor - you change the actual Object Store with the Object Store Editor in the sim ), and that way the property could be set true in the sim, and there's no way a user can change it on a watch. You could have a number of properties to try different things that way too.

    The sim is pretty good at doing things to test a watchface (steps, floors, goals, etc). What kind of things are you trying you can't check out in the sim?
  • Former Member
    Former Member over 8 years ago
    thanks for the advise.

    there is nothing I can't implement in the sim, I agree it's good. I just miss having a framework to write and run lots of UI tests. I also have to have the test code shipped because the compiler won't eliminate it. the unit test framework is useless for anything UI (or am I missing something?).
  • I don't use RunNoEvil, but maybe that's something to look at.

    Also, with 2.3.0, there's a debugger which may help in the sim. No special code.

    As far as removing code, check out build file excludes. Still a change to make a release version, but only in one place.
  • When I developed benchmark app, I used system timer. Start time and end time, then divide to operations quantity performed and get calculation power. I noticed that on real device code executes way slower, than in simulator. All times I run I get Start and End times the same in Simulator, but non-zero on real devices.
    I investigated and found minimal timer tick in Simulator is 16 ms. So create code that runs long enough, but no longer minimal tick in Simulator. Check times before and after run and compare. If time is the same, then you run in Simulator. In real device it will run much slower so timer ticks will be different.

    Earlier SDKs had a version info 0.00 but it is changed, you cannot rely on it.

    function benchmark2()
    {
    // do some stuff here for hard CPU load
    return "ok";
    }


    function isSimulator()
    {
    var t1, t2;
    t1 = Sys.getTimer();
    Sys.println("Benchmark2 start");
    Sys.println(t1);

    Sys.println(benchmark2());
    t2 = Sys.getTimer();
    Sys.println(t2);
    Sys.println((t2 - t1).toFloat()/1000);

    Sys.println("Benchmark2 stop");
    if ( t1 != t2 ) {
    return "real";
    }
    else {
    return "simulator";
    }
    }