Results 1 to 6 of 6

Thread: Unit Test - Problems using Data Source

  1. #1
    Join Date
    Sep 2005
    Posts
    18

    Default Unit Test - Problems using Data Source

    Hello.

    I'm trying to test my DAO implementations and, for this, I wrote a new config file with my test data source definition. But, at the same time, I have to use another config file (the one used in production) because it has another beans definitions.
    I created a subclass of AbstractTransactionalDataSourceSpringContextTests.
    But executing the test I got the following error:
    org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'pt.ptinovacao.invivo.test.promotion.PromotionTest s' defined in null: Unsatisfied dependency expressed through bean property 'dataSource': There are 2 beans of type [interface javax.sql.DataSource] for autowire by type. There should have been 1 to be able to autowire property 'dataSource' of bean 'pt.ptinovacao.invivo.test.promotion.PromotionTest s'.

    How can I say my test to use only the data source I defined for testing?

    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    How can I say my test to use only the data source I defined for testing?
    You can move your production data source definition into a separate application context file, and don't include it in your test.

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Unit Test - Problems using Data Source
    BTW, small point, but that is an integration test. Unit tests just test a single class in isolation.

  4. #4
    Join Date
    Sep 2005
    Posts
    18

    Default

    BTW, small point, but that is an integration test. Unit tests just test a single class in isolation.
    Ok, but to test my DAO class, I need to access the database.
    I didn't understand your point.

    You can move your production data source definition into a separate application context file, and don't include it in your test.
    Is there any another way? This would be a problem for me.

    Thanks.

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Ok, but to test my DAO class, I need to access the database.
    I didn't understand your point.
    Not necessarily - you can use mocks to describe the object behavior and verify that your classes really work. However for integration testing I suggest you take a look at the reference documentation (at the end) and inside the samples code.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Is there any another way?
    Is the difference between prod and test just the datasource properties? If so, you could use the PropertyPlaceholderConfigurer and just replace the properties file for you test.

    This would be a problem for me.
    Can I ask why?

Similar Threads

  1. JBoss 3.2.6 & Spring Deployment issues
    By difranr in forum Container
    Replies: 2
    Last Post: Sep 18th, 2005, 10:08 PM
  2. Separation of integration and unit test source
    By eliot in forum Architecture
    Replies: 4
    Last Post: Jan 30th, 2005, 01:27 PM
  3. Help: the boolean property exception!
    By linwei in forum Swing
    Replies: 2
    Last Post: Nov 17th, 2004, 07:11 PM
  4. Replies: 6
    Last Post: Nov 8th, 2004, 06:43 AM
  5. NameNotFoundException: ejb not bound
    By alesj in forum EJB
    Replies: 2
    Last Post: Oct 19th, 2004, 11:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •