Thanks Craig,

I understand that, i should prepare the backing beans which are under test by hand in the setUp() method, i should not try to validate or read anything from faces-config.xml, is this correct?

Ok then, what about services and DAOs used by these services? For example I am using jmock to test spring managed services (to isolate from the data layer), should i use same principle here? (mock service and dao objects)

I have a backing bean definition like this;

<managed-bean>
        <description>Grades List</description>
        <managed-bean-name>gradeList</managed-bean-name>
        <managed-bean-class> org.mhazer.GradeList</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>serviceLocator</property-name>
            <value>#{serviceLocator}</value>
        </managed-property>
        <managed-property>
            <property-name>visit</property-name>
            <value>#{ sessionScope.visit}</value>
        </managed-property>
        <managed-property>
            <property-name>chosenLessonCode</property-name>
            <value>#{sessionScope.visit.chosenLessonCode }</value>
        </managed-property>
    </managed-bean>

serviceLocator prepares spring managed singleton services which are used to access DB layer, and visit object is used to store session based values. How can i write a unit test for a method of this backing using shale-test framework?

best regards....

On 5/14/06, Craig McClanahan <[EMAIL PROTECTED]> wrote:


On 5/14/06, Murat Hazer < [EMAIL PROTECTED]> wrote:
Hi,

I am trying to write unit tests on my backing beans' action, actionListener and other methods, and using shale-test framework to accomplish this. From TDD principles i know every unit test should test only itself not other functions or layers etc., but in my scenario backing beans use spring managed services and these services also use hibernate managed DAOs, and also these backing beans use other request or session based beans. What are the best practices about unit testing backing beans like this?
 
For the third scenario (need access to other request and session scope beans) you can populate the attributes on the MockHttpServletRequest and MockHttpSession instances.  I do this in the setUp() method of my unit tests.
 

Should i also use mock objects (like jmock or easymock) for these properties of the backing beans? And what should i do to validate faces-config files? I study appfuse (on backing bean tests exceutes all layer functions..) and examples come with shale, they are not very clear (or my misunderstaning), i think i need a clear and nice sample (also other users) unit test on a such complicated backing bean)

regards...
 
--
Murat HAZER
Elektrik-Elektronik Mühendisi - Electrical-Electronics Engineer

Craig
 



--
Murat HAZER
Elektrik-Elektronik Mühendisi - Electrical-Electronics Engineer
Tel - Phone: +90 222 335 05 80 - 1395
Cep Tel - Mobile Phone: +90 532 472 00 63
Blog URL: http://www.projedunyasi.org
Yahoo Group: http://groups.yahoo.com/group/malatyafenlisesi/

Reply via email to