After a long break, recently I came across junit testing. This was when I was helping my team member in writing junit tests and suggested where to start from. Then, there was an issue in running a TestSuite.
The code that I used before is something like below:
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for something");
suite.addTestSuite(SomeClass.class);
return suite;
}
}
But, when i tried to run, I got below error:
java.lang.Exception: No runnable methods
By the way, this is with junit-4. So, here is what we figured out -
In junit-4, they use annotations for TestSuite. So, the old syntax is not working. Here is working syntax
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses( { SomeClass.class})
public class AllTests {
}
So simple. Isn't it?
Also, download junit coverage plugin for eclipse using this update site http://update.eclemma.org/ . More details are here regarding eclemma
Thursday, November 26, 2009
Junit testing
Wednesday, November 18, 2009
Handling "Ctrl+C" in Java
It is very simple. One just need to use addShutdownHook method and pass a thread where you can add code to do what ever you wanted to.
Sample code is here -
public class ShutdownHookDemo {
public static void main(String[] args)
{
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run()
{
System.out.println("Ctrl+C was pressed by some one and I am exiting now");
}
});
int i = 0;
while(true)
{
System.out.println("I value:" + i++);
System.out.println("Going to sleep now for 2 secs");
try{
Thread.currentThread().sleep(2000);
}
catch(InterruptedException ie)
{
System.out.println("Someone woke me up:("+ ie);
ie.printStackTrace();
}
}
}
}
So simple it is.. isn't it? and I just realized that hadoop used it to close files opened when some one press "ctrl+C". Just one sentence to describe it "Simple yet powerful."
Tuesday, November 10, 2009
Lesson-1
While replying to a mail,
taking a pause is MUST and re-read a mail thinking as the person inTO/CC is MUST and ensuring the purpose of the mail meets is MUST.
Monday, November 09, 2009
One year completion of our engagement
Last year, this day Rupesh and I got engaged. Rupesh gave a surprise by preparing a cake in the night (and I was happily sleeping) and we distributed it in our offices. Everyone in my office liked it a lot and were asking for recipe. Seriously, I should confess that it was yummy.
Also, we liked this sharing of our joy by distributing cake in office. :) And, we enjoyed/loved it a lot.