Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
What
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).




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

How

 

  1. In your test, you add an annotation before the class declaration:
    @Resource.File("path/To/preperties/file.properties")


  2.  You define a class member for each property that you want to use with the property annotaion
    @Property("property_name_in_properties_file")
    private String your_property_variable;


  3. Add @Before method to your test class (if it doesn't exist yet) and add following line:
    PropertyLoader.newInstance().populate(this);



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