Open Source & Free  

Test It

Test It

Header Image

One of the common questions we get for Codename One is regarding testability. Cross platform frameworks are notoriously hard to auto-test and so fail when you try to build more complex applications.

We see this as one of the most important areas in which we can innovate and leapfrog native OS environments by offering testing that is just as cross platform as Codename One is. We aren’t just announcing our own unit testing API, we are announcing a fully integrated test recorder to auto-generate GUI tests for your applications and run them on the simulator.

We will also integrate this exact same testing framework into our build server to seamlessly test device support for you in the future.

In the video above you can see me going through the process of recording a test for the kitchen sink and then running it in the simulator.

I’m sure I’m going to get this question so I’ll hit it right now before it comes up. No the tests are not JUnit compatible and we haven’t used another well known testing framework. The main logic behind this is that tools such as JUnit rely on reflection to work since they use annotations or method invocation without an interface. This doesn’t mesh well with Codename One’s device targets so we chose to implement something of our own.

You would have to write most of the test cases for Codename One anyway since the API/functionality would be pretty different.

Notice: This post was automatically converted using a script from an older blogging system. Some elements might not have come out as intended…. If that is the case please let us know via the comments section below.

14 Comments

  • Murali Kumar says:

    No audio in the above video

  • Shai Almog says:

    The video was recorded without audio just to demo the process. We’ll probably do a more thorough tutorial on building automated tests in the future.

  • Hristo Vrigazov says:

    How can we test classes (without the test recorder)?

  • Shai Almog says:

    Tests are just classes that derive abstract test. You can use the test recorder to create a template and then create as many of those as you want purely from code. The test process auto-detects them and runs them.

  • Takii Marskii says:

    Is it possible to just run one Script out of the whole Test Scripts? If so how would I do that?

  • Shai Almog says:

    We don’t provide that option currently.

  • Kumuda Garlapati says:

    I’m new to codename one and trying to find out how we can record and play back help us testing desktop application, how we can install simulator and record and run the tests. any help is really appreciated.

    • Shai Almog says:

      The simulator is a part of the Codename One project. When you run the getting started project it’s there and so is the test recorder. Recorded tests are just source code. You need to add the source to the test package and then you have unit tests.

      • Kumuda Garlapati says:

        ok thanks for the info.

        • Kumuda Garlapati says:

          I was able to record the tests but not able to run them as seeing some errors “java.lang.ClassCastException: class com.codename1.components.InfiniteProgress cannot be cast to class com.codename1.ui.Container (com.codename1.components.InfiniteProgress and com.codename1.ui.Container are in unnamed module of loader com.codename1.impl.javase.ClassPathLoader @6f539caf)”
          Just a question do I need to use specific version of net beans to run tests? I’m not sure what I’m missing here. Thanks

          • Shai Almog says:

            You need to edit the tests after recording. The recording process is imperfect by definition and generates code that might fail and might be too fragile (e.g. fail on a different simulator/device).

            In this case it seems that the failure is triggered by code that shows a progress indicator for a long running task. When recording this wasn’t caught since we skip delays. Otherwise your code would be littered with “sleep” commands. The code is running too quickly and is then running into the InfiniteProgress component which has taken over the form. You need to wait within the test code for the InfiniteProgress to complete.

      • Kumuda Garlapati says:

        Hi Shai Almong, this is the test class that was recorded
        pointerPress(0.5816994f, 0.7446808f, new int[]{0, 1, 0, 0, 0, 1, 0, 1});
        waitFor(149);
        pointerRelease(0.5816994f, 0.7446808f, new int[]{0, 1, 0, 0, 0, 1, 0, 1});
        pointerPress(0.43809524f, 0.425f, new int[]{0, 1, 0, 2, 1, 2, 0, 0});
        waitFor(202);
        pointerRelease(0.43809524f, 0.425f, new int[]{0, 1, 0, 2, 1, 2, 0, 0});
        return true;
        Whenever I try to run encountered error”java.lang.ClassCastException: class com.codename1.components.InfiniteProgress cannot be cast to class com.codename1.ui.Container (com.codename1.components.InfiniteProgress and com.codename1.ui.Container are in unnamed module of loader com.codename1.impl.javase.ClassPathLoader @6f539caf)”

  • Kumuda Garlapati says:

    Thank you Shai Almong for the reply, I always worked with selenium, this is a new thing for me, where do i get documentation on how to code?

  • Kumuda Garlapati says:

    I’m able to record and run test cases, I really appreciate your help on this. thanks

Leave a Reply