There are few tools to make acceptance tests for mobile applications, eg J2ME platform.
The tool J2MEUnit seems a good solution for unit testing tools but compared to Fit frameworks, the tests become more cumbersome.
So I decided to use the test tool Fitnesse to validate business rules in a J2ME application and the tests implemented were simpler and faster. See the instructions to do Test-First approach.
Configuration
To use the tool Fitnesse into eclipse, it is necessary to install Fitnesse plugin for eclipse.
1) Start up Eclipse and select the HELP menu -> Install new software
2) Click the Add button and type in the Name field: Fitnesse and field Location: http://www.bandxi.com/fitnesse/ or usu this Link.
3) Select Ok
4) Select Fitnesse Plugin for Eclipse and then click Next.
5) The Eclipse Plugin will be installed and will restart.
6) When eclipse restarts, the two icons of Fitnesse appear on the toolbar.
Create a Project
1) In eclipse, you click the File menu and select New-> Project.
2) You can select a JavaME Middlet Project.
3) Give a name, for example: FitnesseProject.
4) Select your new project in the left of the eclipse package explorer tab.
5) Select the project created with right click and select Fitnesse -> Add to project classpath libraries fitnesse.
6) Then click again with the right click over the project and select File -> New -> Folder to create a folder.
7) Give the name of the folder: fitnesse
8) Right-click the folder and select Fitnesse-fitnesse> Lunch Fitnesse runtime on this folder.
9) In the name of the project click the right click and select Configure Buildpath
10) In the window to configure Buildpath, add the following jars:
- collections.jar
- ee.minimum.jar
It is necessary because of fitnesse dependences.
11) In your test project, select the src folder with the right click and select: New -> package, give the name of the fixtures this new package.
12) Build a fixture to test for example an calc method.
13) In your test project FitnesseProject go to fixtures package and right click and choose New-> Class
14) In the window to create the new class type the name CalcFixture and in superclass field, click Browse and enter in the window ColumnFixture.
15) Select the class from the list and select Ok to create the class.
16) Write a test fixture with the following code:
package fixtures;
import fit.ColumnFixture;
public class CalcFixture extends ColumnFixture {
public int a, b;
public int result() {
return calc.add(a, b);
}
}
The line return calc.add(a, b); is gonna be red because the method add does not exist.
Lets create the system code:
17) In your project, create a new package called app (src right click and select: New -> package,).
18) Create a new Class in this package called Calc.
19) Insert a code just to fix the error in your fixture.
package app;
public class Calc {
public int add(int a, int b){
return 0;
}
}
Now the error in your fixture will disappear.
Executing Tests
1) In the eclipse toolbar, click the icon to launch the Fitnesse server.
2) the eclipse browser will appear in the eclipse fitnesse page.
3) the page is similar to a Fitnesse wiki, click the Edit menu on the left top of the page.
4) Enter the word anywhere ProjectTest and save the change.
5) You will see the word followed by a question ProjectTest?
6) Click the interrogation ? mark.
7) You will see an edit page of a wiki.
8) Enter the following code in the wiki:
!path /C :/workspace/FitnesseProject/bin
! 3 Column Fixture
|!-fixtures.CalcFixture-! |
| a | b | result () |
| 1 | 2 | 3 |
| 13 | 5 | 18|
It is important to point to the bin folder of the the project using !path.
To indicate the package and fixture class to be used, we use the command |!-packagename.classname-! |
Then the decision table is implemented with the parameters to be passed, text separator and the expected return result class ().
9) Save the page in the wiki.
10) In the page saved, select the blue menu on the left Properties.
11) On page properties select Test and then click Save Properties.
12) When you return to your test wiki the button Test will appear in the menu.
13) Click the Test to run your test.
14) If a message in yellow saying there was not found the test class or fields, make sure the project generated classes in the bin folder or you are pointing to the correct address in the bin folder.
15) Another important check is if you put the exact same name as the parameter of the fixture in the table.
16) If the test run the errors in red will appear as the picture bellow:
The errors appear because the method add in the class Calc wasn't implemented.
17) Back to project and open the class: src -> app -> Calc.java.
18)Insert the code:
package app;
public class Calc {
public int add(int a, int b){
return a+b;
}
}
19) Save and back to Fitnesse page in the eclipse.
20) Don't forget to build the project.
21) Execute the fitnesse tests again clicking in Test.
22) The test table will be green, your test is passed as the picture bellow.
23) When your class will be totally tested, you can create a middlet and call your class Calc.
24) In src, right click and create the package with the name mobile in New-> package.
25) In the package created click the right mouse button and create a midlet. New-> midlet
26) Put the name of the HelloWorld midlet for example.
27) In midlet created add a private variable private Display display;.
28) In the startApp () put the following code:
Display display = Display.getDisplay (this);
String message = String.valueOf(new Calc().add(3, 4));
TextBox textBox = new TextBox ("Hello World", message, 50, 0);
display.setCurrent (textBox);
30) Run the midlet selecting the project and clicking the right click and selecting: Run As -> Emulated Java ME Midlet
31) The midlet will run Hello World and will appear the result of add: 7.
For the next functionalities, repeat all the process :)
Fitnesse pros:
- A fixture class tests one class of the system.
- Parameters are passed only in wiki and it is not necessary one test method for each parameter (as JUnit).
- It is friendly and developers and Testers can use the eclipse itself.
Fitnesse cons:
- Tests are run only in eclipse and it is not possible to embed the tests in the emulator or in the cell phone as J2MEUnit do.
My Conclusion is:
If you want to validate business rules and acceptance criteria, the Fitnesse works well and fast. But if the developer wants to analyze the memory limits and the cell phone performance, so J2MEUnit and Manual tests are required.
Hi Eliane,
ReplyDeleteEclipse throwing error to connect this link.
http://www.bandxi.com/fitnesse/
Please let me know is this link still valid or changed.
Thnaks,
Shaz
Hello Shaz,
ReplyDeleteThis link is not available, I found out this plugin for eclipse: http://fitnesse-editor.googlecode.com/svn/trunk/fiteditSite/
I just installed in my eclipse using Help -> Inatall new Software
The Fitnesse menu will appears and you can Open Fitnesse Tests and run in the eclipse browser.
Please, tell me if this new plugin really works for you,
Best Regards,
Hi Eliane,
ReplyDeleteI have installed the plugin as per your comment, after creating a project I am not able to add the Fitnesse library to the Folder created. It says open Fitnesse in browser. I am using Eclipse Indigo version. Would be nice if you can help me in resolving the issue.
Hello Suresh, I will try to send to you the fitnesse plugin by e-mail and you can add manually, ok?
ReplyDeleteGreat, Its working fine. . . Thank you. :-)
DeleteNice Blog . .
It looks like the link http://www.bandxi.com/fitnesse/ is no longer valid.
ReplyDeleteAnother cool trick with Fitnesse is the ability to add JavaScript to the pages and work with the REST api. I wrote an article expanding the usefulness of suites -- http://www.evonsdesigns.com/2014/03/getting-most-out-of-fitnesse-suites.html
Hi Eliane,
ReplyDeleteEven I have installed the plugin as per your comment, after creating a project I am not able to add the Fitnesse library to the Folder created. It says open Fitnesse in browser. I am using Eclipse Indigo version. Would be nice if you can help me in resolving the issue.Can you please send me the plugin by e-mail??