RSS

About Shale Testing Framework

08 Jan

Shale Framework:

Its Features:

The Shale Test Framework provides mock object libraries, plus base classes for creating your own JUnit TestCases. It utilizes a library of mock objects — classes that implement and emulate the container APIs, but still run in the isolated environment of a JUnit test case. It provides mock object implementations for its own features, as well as features of the underlying container (Servlet and JavaServer Faces) environment. In addition, convenient base classes are provided to make it very easy to build your own test cases utilizing these mock objects. Shale Test Framework is almost an actual mock implementation of the JSF spec.

Benefits of using Shell Testing framework:

Unit testing with JSF is mainly focused on the testing of managed beans, converters, valuators and other stuff. Most of the business logic is generally located in managed beans and since these beans are actually ordinary java POJOs, it is too hard to figure out the way for testing. The tricky parts may be the ones where JSF stuff like FacesContext is involved.

Shale testing framework has shown a way to make the backing beans of the pages aware of the JSF lifecycle.

Moreover it initializes a number of required variables which are needed to test the JSF specific cases. The set of initialized variables includes (variable name and type):

  • application (MockApplication)
  • config (MockServletConfig)
  • externalContext (MockExternalContext)
  • facesContext (MockFacesContext)
  • lifecycle (MockLifecycle)
  • request (MockHttpServletRequest)
  • response (MockHttpServletResonse)
  • servletContext (MockServletContext)
  • session (MockHttpSession)

Configuration

There is nothing to be done to implement shale testing framework into our application framework. We need to just add the required jar named:

shale-test.jar

The test class is required to extend the abstract class AbstractViewControllerTestCase.

public class SomeBeanBackingBeanTest extends AbstractViewControllerTestCase{
   ................
 }

While extending the class we do have to provide a public constructor with one String argument of the class which calls super with the provided argument.


public class SomeBeanBackingBeanTest extends AbstractViewControllerTestCase{          ................
 public SomeBeanBackingBeanTest(String arg0) {
super(arg0);
  }
 }

Create a setUp() method and that will call  super.setUp(). This method will be called by JUnit immediately before it executes each test method. After the call to the super class setUp() method, perform any other initialization required to execute the tests in this test case.

tearDown() method cleans up any custom variables allocated in setUp() method, and then calls the super.tearDown() method. This will be called by JUnit after each test is executed.

public class SomeBeanBackingBeanTest extends AbstractViewControllerTestCase{          
................ 
publicSomeBeanBackingBeanTest(String arg0) {
super(arg0);
}
@Override
public void setUp(){
try {
super.setUp();
.................
.......................

} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void tearDown(){
try {
super.tearDown();
instactVaribles = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}

Now, one or more individual tests methods (which must be public, return void, take no arguments, and have a method name of the form testXXXX can be created to test the functionalities.

Advertisements
 
1 Comment

Posted by on January 8, 2009 in Shale Testing Framework

 

One response to “About Shale Testing Framework

  1. Mike

    January 9, 2009 at 2:08 pm

    Thanks for this article. It was easy to read and understand. 🙂

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: