Skip to Content
Author's profile photo Former Member

A Convenient way to work with properties in junit

In this post, I will present a convenient way to work with properties file inside unit tests.
This way requires properties, which is a project on Gitgub.
(To find out how get started and install properties, please read their official documentation from the link above).

You have a properties file that is used in production. That means that production code depends on values in this file.
You want to use the same values in your test.



  1. In your test, you add an annotation before the class declaration:
  2.  You define a class member for each property that you want to use with the property annotaion
        private String your_property_variable;
  3. Add @Before method to your test class (if it doesn’t exist yet) and add following line:

Now, in your test, you can access each property from properties file using an internal class member.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.