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.
20 Comments
No audio in the above video
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.
How can we test classes (without the test recorder)?
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.
Is it possible to just run one Script out of the whole Test Scripts? If so how would I do that?
We don’t provide that option currently.
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.
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.
ok thanks for the info.
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
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.
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)”
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?
I’m able to record and run test cases, I really appreciate your help on this. thanks
Hi Shai Almong, I have a question as we are using test recorder and question is once I record all the tests and when running is it able to handle different screen resolutions?
Not seamlessly. We try to generate “logical code” but can’t always detect that correctly.
Got it. thank you.
Hi Shai Almog, Sorry for bothering you, have a question on whether the .apk file provided to us by developers can be integrated with appium framework are there any limitations or is it compatible? as we have selenium framework for ui and want to have this application embedded into it for better management. Really appreciate your help on this.
Hi,
We don’t have any support for Appium. It might be possible to build something like that or adapt existing APIs into a cn1lib but there was no effort in that direction.
Thank you for the reply, I will have conversation with developers.