Creating project and simple test model

Contents

Prerequisites

Basics – equivalence class tree model

Adding test classes to a model

Adding test methods

Importing test methods

Importing test classes

Modeling test methods

Adding choices to parameters

Choices’ special values

User type parameters

Manual definition of test cases

Prerequisites

This tutorial assumes that you:

  • have installed Eclipse IDE
  • have installed ecFeed plugin. If you do not, please install the plugin according to the tutorial Installation of ecFeed as Eclipse plugin.
  • know the basics of Java and can use Eclipse IDE

Remarks

This tutorial is based on ecFeed plugin integrated into Eclipse IDE. Also standalone ecFeed application supports many of described below operations. Standalone application has no access to Java project and Java source code, which is available in Eclipse IDE. As a result, in standalone application user can not use functions which have anything in common with the Java source code:

  • Implementation of source code.
  • Display of the implementation statuses.
  • Import of implemented source code methods.
  • Calling compiled Java code in order to execute test.

Basics – equivalence class tree model

Create a new java project in Eclipse (you can name it “tutorial”). Then go to File->New->Other… and select ecFeed->New Equivalence Class Tree file. Press Next button and on the next screen select the desired location and name of your new file. We will choose the ‘src’ folder. You can name the file “tutorial.ect”. Press Finish. You have just created an empty ecFeed project.

The main editor window is split in two parts. On the left hand side you can navigate the model tree. We will call it “master page”. Currently selected node can be edited in the right panel, called “details page”. Some operations (e.g. copy&paste) are available in nodes’ context menu by right clicking on a node in the master page.

Adding test classes to a model

The root node of our project gathers different test classes. At the moment we have no classes in our model. We can add a class by clicking New test class button under the Classes viewer in the model details page.

The classes viewer now contains new class com.example.test.TestClass. You can change package and name of the new class by editing it directly in the viewer, but at the moment let’s keep it as is. When you expand the model node in the master page you will see that the TestClass node is decorated with a red traffic light symbol. This means that the class has no implementation in our java project. To change it, just click on implement button in the top right corner of the project details page. This button will implement all classes in the current project that are not implemented. You should see now that your java project has a new package in the ‘src’ folder called com.example.test. The package contains empty class TestClass. You can open the source code of the currently selected class by clicking on goto_impl button.

When you go back to the model editor you will see that the red traffic light decoration of our TestClass icon turned green. This means that the class is implemented.

unimplemented_class

Adding test methods

Now our test class model is empty. We can change it by adding some test methods. This is done in the class details page. Press Add new method button under the Methods viewer. Also, you can just select “Add method” item from the class item context menu. Once you do it, you should notice two things:

  1. A new method testMethod() has been added to the class model. The method is not implemented, so in the model viewer it is marked with red light.
  2. The green light next to TestClass node turned yellow. The yellow color means that the node is “partially implemented”. The node itself has implementation in java project, but some of it’s children do not. In this case our TestClass is implemented, but the testMethod is not.

You can click on implement button again, or manually add following code to the TestClass implementation:

public void testMethod(){
    System.out.println("Hey, it's me - your test method!");
}

When you add implementation of such a method to TestClass, the light should go green again.

Importing test methods

We can also add a method to our model by importing it from the code. Let’s first implement a following method in our TestClass:

public void testMethod(boolean arg1){
    System.out.println("testMethod(" + arg1 + ");");
}

Now go to details page of TestClass. You should notice new viewer called Other methods in TestClass. In this viewer you can see all methods in the class implementation, that are not modeled and can be imported. Such methods must be public and return no value. They must accept only primitive types or enums as parameters. Mark the method you just added to the code and click Add selected button. The method has been added to our model and turned green right away. The Other methods viewer should disappear, unless you added some more functions to your class code.

tutorial-basic_features-other_methods_section

Importing test classes

EcFeed also allows to import entire Java classes into a model.

Let’s create following class in com.example.test package:

package com.example.test;
public class TestClass2 {
    public void testMethod(String arg0) {
        System.out.println("testMethod2(" + arg0 + ")");
    }
}

To import the class with all methods to our model go to the model details page in the model editor and press the Add implemented class button below class viewer. You will see a dialog where you can select the class you want to import. Find and select the TestClass2 class (not a symbol of the compilation unit but a class icon). If you want to import only methods annotated with @Test annotation, check the Import only methods annotated with @Test checkbox. Otherwise all methods with primitive or enum parameters that return void will be imported. Now press OK. The class TestClass2 with testMethod(String arg0) have been imported to our model.

Modeling test methods

Go to details page of testMethod() of the TestClass. You can change its name or use Browse button to reassign the model to another function with the same parameter types that are in the class implementation (there are no such functions yet). If you click Test online button you will execute the function. The meaning of this button is much more complicated, but we will get to it.

Click Add parameter button under the Parameters viewer. You just added an int parameter named arg0 to the method model. Note that the method became unimplemented right away. You can change parameter’s name, type or Expected flag (the meaning of the latter will be explained in another tutorial). You cannot create a model of a function with a name and parameter types that in already in the class model, so you will not be able change arg0 type to boolean.

Adding choices to parameters

A parameter type can be chosen from a combo, or typed directly in the text field. If you type there a type name that is neither one of Java primitive types (“int”, “long” etc.) nor “String”, it will be considered as user type parameter. User type parameters in order to be implemented should be prefixed with Java package name. Default package is not allowed in this case.

Now add two more parameters to testMethod(int arg) and change their types boolean and com.example.test.MyType respectively, so the method has following signature: testMethod(int arg, boolean arg1, MyType arg2).

If you expand the method node you will notice a node for each parameter of the method. The first parameter arg: int is implemented, but the other aren’t. Go to the details page of the boolean argument. You will see fields where you can change parameter name and type. Let’s skip the “Default value” and “Expected” properties and look at the “Choices” viewer. This is where the fun begins. Adding choice to function parameters is the core part of the equivalence class concept. Currently there are no choices in the viewer so let’s add two. Change their names to true and false and set their values to true and false respectively. When you add first choice to the parameter model, the implementation indicator of the boolean parameter should change to green.

Choice’s special values

Note the when you add a new parameter to a method, it already has some default choices: MIN_VALUE and MAX_VALUE. These are special values of the parameter. Each built in Java type has different set of special value parameters, for example in String type it is /null. You can find out special values of parameters by expanding a combo in the choice value edit field in choices viewer or choice details page.

User type parameters

Now let’s go to the details page of the last parameter (the one with user type). We want to have two choices for this parameter. Edit their names to value 1 and value 2 and set their values to VAL1 and VAL2 respectively. Values of user type parameters must follow the rules of naming enum values in Java. Even though we added choices to the parameter, the implementation indicator for the parameter did not changed as for boolean parameter. This is because the com.example.test.MyType type is indeed not implemented. We can implement it easily by the magic implement button. Once you clicked it, you should see that MyType enum has appeared in the “com.example.test” package with following content:

package com.example.test;

public enum MyType{
VAL1, VAL2
}

tutorial-implemented_user_type

Now the parameter node should change implementation status indicator, yet the method node shows that is is still not implemented. The reason is obvious: we have the testMethod() implementation, but not testMethod(int arg0, boolean arg1, MyType arg2). Let ecFeed implement the method, so that following code will be added to the “TestClass: file:

public void testMethod(int arg0, boolean arg1, MyType arg2) {
    // TODO Auto-generated method stub
    System.out.println("testMethod(" + arg0 + ", " + arg1 + ", " + arg2 + ")");
}

If you try to implement the method without having com.example.test.MyType type implemented first, it would get automatically implemented together with the method. This is a general rule: children elements got implemented (if it is possible) with their parents.

Manual definition of test cases

Now we can add some test cases to our method. A test case is combination of choices representing method’s parameters. The method has three parameters. The first one is integer and it is represented by two choices: “min value” and “max value” that were added to the parameter model by default. We have manually added choices to the other two parameters. So in total we have three parameters with two choice each. A test case will be a combination of these parameters.

Click “Add test case” button in the “Test cases” section of the method details page. You will see a dialog, where you can define combination of choices that will be used as parameters in the test case. You can change a name of the test suite where the test case belongs. Click OK. The Test cases viewer now shows 1 test case in the default suite suite. The test case is green, which means that it is executable. You can execute it by checking the box next to it and clicking Execute selected button.

tutorial-add_test_case