Announcement Announcement Module
Collapse
No announcement yet.
access bean id by name from my unit testing. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • access bean id by name from my unit testing.

    i am writing a test for my spring app.

    what i wanted to do is pre-fillup a set of javabeans, for example:

    Code:
    <bean id="name" class="com.Name">
        <set property="firstname">Sample</property>
        <set property="address">Beverly hiils</property>
    </bean>
    
    <bean id="grades" class="com.Grades">
        <set property="quarter">1rst Quarter</property>
        <set property="grade">80</property>    
    </bean>

    my problem is i need to use those bean from my test case.

    is there a way to access them like this or any way like this:

    Code:
    public void testSample&#40;&#41;&#123;
        Name name = context.get&#40;"name"&#41;;
        Grade grade = context.get&#40;"grade"&#41;;
    &#125;

    any help will be very much appreciated.

    thanks a lot in advance.

  • #2
    I think this would work,

    as long as the you are creating an ApplicationContext based on the xml above.

    and then get the beans from ApplicationContext.getBean(bean_id)

    Comment


    • #3
      Re: access bean id by name from my unit testing.

      Originally posted by cyber
      Code:
      public void testSample&#40;&#41;&#123;
          Name name = context.get&#40;"name"&#41;;
          Grade grade = context.get&#40;"grade"&#41;;
      &#125;
      Another approach (if you must use the context for testing) is to use the Spring Mock module which allows you to wire JUnit tests without using the 'get'.

      J. Betancourt

      Comment


      • #4
        thx... will do both of your suggestion.

        Comment

        Working...
        X