­
­

Writing Parameterized Test Cases in Junit

Many times we want to execute the same test case with different input and expectations. Instead of writing each test separately, it is much better to abstract the actual test into a class and inject input values and expected results into the test class. Junit4 provides Parametrized test, which is a standard solution to achieve this. Let’s write a simple square() method to...

Continue Reading

Creating temporary files or folders in Junit

Numerous times we write Junit tests where we need to create temporary files and folders for executing the testcase. Usually, we create temporary folder at some physical location and write temporary files in it. Major pain in this approach is that we need to take care of creation and cleanup of all such files during the test lifecycle. Junit4 comes with special Rule TemporaryFolder which automatically takes care...

Continue Reading

Repeating a test case in Junit

Many times we need to create Junit tests which needs to be repeated over and over (may be with different data set). Many of us did this by writing custom Runner or sometimes using parameterized test. Junit4 comes with @Rule, which can be used for repeating a testcase. Actually, rules are used to add additional functionality which applies to all tests within a...

Continue Reading

Correct way to check empty string in JAVA

In our day-to-day programming activities, we usually come across multiple scenarios where we need to check whether a string is empty or not. There are multiple ways to do this check in Java: equals method: str.equals(“”) length method: str.length() == 0  //recommended isEmpty method [From Java 1.6 onward]: str.isEmpty()  //recommended The recommended way for empty string check is length() or isEmpty() method. We should never use...

Continue Reading

String Constant Pool In Java

String is a special class in Java. It has very high importance in concurrent programming as well because String is immutable. Since, String is immutable, so they should be reused. In order to reuse String objects JVM maintains a special pool called “String literal pool” or “String constant pool” to store references of String Objects. There are slight differences in various methods of...

Continue Reading

Recursion and StackOverflowError in Java

Recursion simply means calling the same function inside its own body repeatedly to complete some task. This is one of the standard approaches to achieve some task. While programming using recursion, there is one basic thing one must fix is the base condition to stop the recursion, otherwise we’ll run into an infinite recursion. Let’s have a look on a very simple recursive function...

Continue Reading

Using Unix Commands On Windows

In our day to day life, we need to debug various issues with the help of several log files e.g. application logs, server access logs, error logs etc. and during this process we try to fetch relevant information from the log file(s). While working on windows with such files, we use various editors like Notepad++, JujuEdit etc. But, what if the log files are...

Continue Reading