Accessing Configuration from Unit Tests

1,706 views
Skip to first unread message

Cemo Koc

unread,
Aug 15, 2012, 5:40:34 PM8/15/12
to dropwiz...@googlegroups.com
Hi,

I have been practicing with DW and trying to write some unit tests including configuration classes. 

As a simple example I would like to read database connection setting from my application.yaml file for my JDBI DAO environment.

Thanks

 
Message has been deleted

jvelo

unread,
Aug 17, 2012, 5:49:27 AM8/17/12
to dropwiz...@googlegroups.com
Hi,

You can checkout tests classes in https://github.com/codahale/dropwizard/tree/master/dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests. See the setup method of GzipConfigurationTest (or any *ConfigurationTest).

IMO such tests do not bring much to the table, maybe you would be better off with integration tests for testing configuration settings.

Hope this helps,
Jerome

Cemo Koc

unread,
Aug 17, 2012, 3:44:11 PM8/17/12
to dropwiz...@googlegroups.com
Hi Jerome,

I actually checked these classes but wanted to be sure that what is the best practice to generate configurations.

Thanks

17 Ağustos 2012 Cuma 12:49:27 UTC+3 tarihinde jvelo yazdı:

Tatu Saloranta

unread,
Aug 17, 2012, 6:19:50 PM8/17/12
to dropwiz...@googlegroups.com
On Fri, Aug 17, 2012 at 12:44 PM, Cemo Koc <cemalet...@gmail.com> wrote:
> Hi Jerome,
>
> I actually checked these classes but wanted to be sure that what is the best
> practice to generate configurations.

If you mean generating JSON/YAML config files, are you doing that for
test purposes, or deployment?
For testing, actual files are not needed at all -- just pass the
Config object(s). No need to create intermediate artifacts.

For deployment, you can generate them from Config instances as well,
programmatically, if you want.

-+ Tatu +-

Cemo Koc

unread,
Aug 18, 2012, 5:14:10 PM8/18/12
to dropwiz...@googlegroups.com
Hi Tatu,

I would like to create configuration instances at my test cases. 

Actually I want to have glue codes for JUnit, DBUnit and Dropwizard. For me it is fitting better when I will have dynamically changing database because of the nature of our system. Instead of hardcoding  database configurations as a localhost, It can be great to read configuration file for test cases.  

BTW, I am a big fan of you. :)

Thanks for your attention.



18 Ağustos 2012 Cumartesi 01:19:50 UTC+3 tarihinde Tatu Saloranta yazdı:

Tatu Saloranta

unread,
Aug 18, 2012, 6:12:37 PM8/18/12
to dropwiz...@googlegroups.com
On Sat, Aug 18, 2012 at 2:14 PM, Cemo Koc <cemalet...@gmail.com> wrote:
> Hi Tatu,
>
> I would like to create configuration instances at my test cases.

Ok. One thing I did have to do was to add setter methods, since
properties tended to be protected (not public), for core properties.
And I usually define my own configuration properties as public, since
I control all code and need not ensure immutability.

> Actually I want to have glue codes for JUnit, DBUnit and Dropwizard. For me
> it is fitting better when I will have dynamically changing database because
> of the nature of our system. Instead of hardcoding database configurations
> as a localhost, It can be great to read configuration file for test cases.

Definitely.

>
> BTW, I am a big fan of you. :)

Thanks!

>
> Thanks for your attention.

No problem -- I think this mailing list is nice in that people are
learning & sharing ideas, quite productive as far as lists go.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages