Month: November 2014

Learn IT, Girl

Learn IT, Girl is an international mentor-ship program where women all over the world get chance to learn a new language through a project and with the support with the mentor.

The official website : https://sites.google.com/site/learnitgirl

I am a mentee this round. My mentor is Kesha Shah. We are developing an expense splitter to handle shared expenses with Ruby.

I will be continuously blogging about the progress of the project. So keep in touch!!

 

Season of KDE

Season of KDE is an outreach program hosted by KDE community. It is a similar program like “Google Summer of Code”. The current round of Season of Code started in October and hope to go until January.

I am selected for Season of KDE with the project “Theme Designing for Pairs”. My mentor is Heena Mahour. Pairs is a KDE educational project focused on preschool children. It helps stimulating memory and logic skills of children. My project will cover the following aspects of “Pairs”.

  • Creating and adding new themes
  • Improve documentation
  • Re factor code base

When I found about SoK, I was looking for opportunities to contribute to open source community. My skills in creativity, technical documentation will help me to achieve the expected results very easily.

Why do it in the hard way : A guide to JUnit Parameterized Tests

If you have a set of parameters that your method should be tested, here is an easy way. For an example, let’s take that you have a method to find a number is even or not. You want to test that for some random set of given numbers, whether the method works fine.

The method in Java to find even numbers looks like this:


public class EvenNumberChecker {
public boolean checkForEvenNumber(int number){
boolean isEven=false;
if(number%2==0){
System.out.println("Number "+number+" is Even");
isEven=true;
}else{
System.out.println("Number "+number+" is Odd");
isEven=false;
}
return isEven;
}
}

Then here is where the magic comes in. You have to create a JUnit test case and annotate it with @RunWith(Parameterized.class). Then you have to create the constructor using the parameters to be tested as an arguments. Then annotate a method with @Parameterized.Parameters and add the parameters to be tested through this method. You have to be careful that this method should return an iterable list. Here is what the whole test case looks like.


@RunWith(Parameterized.class)
public class TestEvenNumberChecker {
private EvenNumberChecker evenNumberChecker;
private Integer inputNumber;
private boolean isEven;

@Before
public void initialize() {
evenNumberChecker = new EvenNumberChecker();
}

// Parameter to be tested should be an argument here.
// In this case we have two parameters, that is the input number and the boolean value of indicating whether the number is even.
public TestEvenNumberChecker(Integer inputNumber,boolean isEven) {
this.isEven=isEven;
this.inputNumber = inputNumber;
}

// We have to add the parameters to be tested through this method
@Parameterized.Parameters
public static Collection Numbers() {
return Arrays.asList(new Object[][]{{2314,true},{456834,true},{678423,false},{4632489,false}});
}

@Test
public void testPrimeNumberChecker() {
System.out.println(“Checking Number : “+inputNumber);
assertEquals(isEven, evenNumberChecker.checkForEvenNumber(inputNumber));
}
}

You can download the full implementation at https://github.com/sandarumk/ParameterizedTestTutorial