JUnit Tutorial

Here is really brief JUnit Tutorial. Without a wait, lets start.

What you need ?

Make sure that you have all of the jars in right place.

Let’s Start !

You need a piece of code that you want to test with JUnit, we will start with this simple example :

public class Math {
        static public int addMee(int int1, int int2) {  
                return int1 + int2;
        }
}

What it will do ?, just add two numbers.  Now you need to write a piece of code that you will be writing to test. For this, you need :

  • import junit.framework.*
  • extend TestCase.

Here’s an example JUnit piece of Code.

import junit.framework.*;

public class TestMath extends TestCase {

  public void testAdd() {
        int num1 = 3;
        int num2 = 2;
        int total = 5;
        int sum = 0;
        sum = Math.addMe(num1, num2);
        assertEquals(sum, total);
  }
}

There are couple of things that you need to look for :

  1. The method is named testAddNumbers. This convention tells you that the routine is supposed to be a test and that it’s targetting the “addNum” functionality.
  2. Now how to you run yout test code ?, here we use Ant to do the task for us (you can also use command line, Eclipse or the JUnit Test Runner). To run a Junit test with an Ant script, add this to your Ant script:

<junit printsummary=”yes” haltonfailure=”yes” showoutput=”yes” >
        <classpath>
                <pathelement path=”${build}”/>
        </classpath>                   

        <batchtest fork=”yes” todir=”${reports}/raw/”>
                <formatter type=”xml”/>
                <fileset dir=”${src}”>
                        <include name=”**/*Test*.java”/>
                </fileset>
        </batchtest>
</junit>
     
Ant will also do nice things like create nice HTML reports for you!, and this is all and should be enough for you to understand the basics of Junit.

Blu-ray DRM defeated

First it was HD-DVD and now, Blu-Ray. So we have almost all of the DRM’s un-protected. This is goint to get scary for the ones who make DRMs.

The latest Blu-ray hack was performed by muslix64 using a media file provided by Janvitos, through the video resource site Doom9, and applied to a Blu-ray copy of the movie Lord of War. In this case, muslix64 didn’t even need access to a Blu-ray player to nobble the DRM protection included on the title.

Both HD DVD and Blu-ray use HDCP (High-Bandwidth Digital Content Protection) for playback display authentication and similar implementations of AACS (Advanced Access Content System) for content encryption.

More here.
Update: BD+ is still undefeated.

Akismet Anti-Spam Plugin for WordPress

Spam has always been an issue for all types of blogs. But if you are using WordPress then you have a good solution Akismet is a really nice plugin for WordPress. That would definately stop spam for you (means your blog) .

Updated to a new theme !

I happened to saw a really good theme on http://www.hoofei.com, the theme really caught my eyes, and i didnt wasted any time to make it double bonus. WordPress 2.1 + New Theme. Great work Hoofei.

The only missing part is that now i need to change the Logo also :).

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.