can java be simple?

Sunday, January 30, 2005

Testing Tapestry

Decision

1. Postpone testing of tapestry application
2. Start JUnit testing of domain objects
- any need to mock the hibernate classes?
- investigate how to use dbunit
3. document tapestry testing status
4. ask questions


DOCUMENTING TAPESTRY TESTING STATUS

1. What should the objectives of testing be? Illustrate with example requirements and code
2. What is the best apporach to testing?
3. What is the best apporach to testing a web application?
4. What makes a tapestry application? Understanding what i am testing - the classes/framework, etc
5. Do I need Mock Objects?
6. Why I decided to use Mock Objects
7. Which is possible? Which makes sense?
A. integration-tesing tapestry in container a la cactus, servletUnit. investigate this for jsp, servlets, read pdfs again
B. integration-tesing tapestry outside container - Mocks
8. What are the pros and cons of the various Mock libraries?
9. Is EasyMock suitable for my case
10* Using Mocks. It appears there are 2 approaches:
1. Write my target class and call mock collaborators. The Mock collaborators test(verify correct usage) = integration?
2. Write my target class calling real objects. Write tests to test the class passing mocks a la junit

11. My experience:

1. I tried using EasyMock to test a tapestry page using the testCase approach of writing a class first and writing a test class for it. I did not use TestAssist becos it was not needed yet.

2. Problem method: AbstractComponent.getBeans();
method code:
When my method tries to call getBeans(), i get the error null because getBeans returns a null object.
1. This happens because getBeans() is implemented in a superclass of my Page class called AbstractComponent which i did not write. I wrote the subclass to AbstractComponent which is my Page class. AbstractComponent is part of the Tapestry framework code. The problem arises from the fact that i did not initialise my page object well becos i just called new to instantiate it and did not set the necessary properties. this is made worse becos the beans property has no mutator/set method.

possible solutions appear to be:

1. mock the superclass AbstractComponent and return a mock beans
2. mock the getBeans method probably by creating a mock method in my Page class. EasyMock cant help here
3. Use the actual framework classes to instantiate my Page class properly.

A big question is: Does it make sense to mock the framework-provided superclass of my Page class? Isnt that equal to mocking aspects of my target domain class that i am testing?

Currently, i am using EasyMock for which i dont know how to mock a superclass of the class i am testing.

A. is it possible to mock a superclass of the class i am testing and set it as the superclass of my class?
B. does EasyMock support it?
C. do Dynamic Mocking libraries support this?
D. Which Mock libraries support this?

An possible solutions is to mix dynamic mocking with generated mocks so that i dynamically call mocks in my test code but generate a concrete mock superclass that my class inherits from.

Other Questions

0. does it make sense to test the tapestry page?
1. Should i test the tapestry page while isolating the tapestry framework?
2. Should i mock every class in the tapestry framework including BasePage, my page class superclass?
3. To effectively test a tapestry app, do i need to similate the full framework and the servlet container?

Note: My primary objective was to test the QuestionnairePage class in isolation. However,

1. the page inherits from another class that is part of the framework. Should i mock this superclass?

Does it make any sense to test a tapestry page class outside the framework?

Are the User-written pages and the framework so tightly coupled that it does NOT make sense to test the page in isolation?

My immediate requirement is how to get Mock superclass for the class i am testing using EasyMock, and if not possible any mocking approach.

Possibilities:

1. Find out a way to do it with EasyMock
2. Combine a static 'class generating' mock library

OUTLETS

1. My blog
2. the serverside discussions
3. the serverside questions
4. javalobby
5. testing mailing lists
6. Mocking mailing lists
7. EasyMock mailing lists
8. tapestry mailing lists
9. howard blog
10. mail to gurus - tapestry, web, testing, mocking mailto:mike@krisnmike.com
11. download and read articles

resuming

hi all, i hv been a registered user of jroller for a while but i hv finally decided to start using this my blogspot blog which i registered after my jroller account. d only reason i registered this blogspot blog then was becos i was required to do so before posting a comment or something.

however, though i am not a regular blogger, i wuz about to make a post to jroller yesterday and there was no textarea to type in in my posting area. what's with that? then i remember i hv a blogspot account, tried it and it's so cool. hence another beginning..

i will bring in my jroller posts here as well and render my jroller account deprecated.

Thank you, the developers of blogspot/ blogger/ google whatever.