LeanFT

LeanFT Java Tutorial Part 6 – Parameterizing Tests

Since we are working with Junit framework, we’ll have to deal with some of its limitations. One of them being that our test methods can not have parameters passed to them while being called(although there are other ways to do this but they are way too complicated). Lets focus on a simple approach that we can use:-

Our Eclipse project has a leanft.properties file which is used to set some properties for the Runtime engine. We can put our parameters inside this file and read them during execution. A sample properties file in which i have added 2 custom keys looks like this:-

# ===========================================
# SDK Settings
### To change behavior, uncomment relevant options. 
# ===========================================

#The Username to be used while logging in
username="kohli_harshit@learn2automate.com"

#The Password to be used while logging in
password="l2a"

Now if we have a test method which needs to use these keys, our c# code will look something like this:-


 @Test
 public void testLogin(){
 try
 { 
 FileInputStream iStr = new FileInputStream("resources\\leanft.properties");
 Properties prop = new Properties();
 prop.load(iStr);
 
 
 String uName = prop.getProperty("username");
 String pwd = prop.getProperty("password");
 
 //test the login function here
 

This way we can parameterize our JUnit test methods. One thing that I would like to put forward here is that this is a very simple way of doing this and we can do much better with other testing frameworks like TestNG which I’ll be covering in the later posts.

LeanFT Java Tutorial Part 7 – Using Insight Objects

Happy Automating !
Harshit Kohli

Advertisements

Categories: LeanFT

Tagged as: , , , , ,

6 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s