Announcement Announcement Module
Collapse
No announcement yet.
Unit Test - Problems using Data Source Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


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

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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?

            Comment

            Working...
            X