Monday, July 12, 2010

Be aware when extending the base class

Kindly take note when extending the base class from a sub class:
  1. Subclass static method can not override Baseclass instance method, otherwise an error static method can't hide instance method from Baseclass will be prompt.
  2. Subclass instance method can not override Baseclass static method, otherwise an error instance method cannot override the static method form Baseclass will be prompt.
Happy programming @!

Sunday, July 11, 2010

To execute a java program

I don’t know that a java program can be executed in two ways. Here we go:

First Method

Compile java source into java byte code, and then execute it right from the byte code.

javac -sourcepath src -d build\classes src\org\huahsin68\
java -cp build\classes org.huahsin68.HelloWorld

Second Method

Build a jar file from the byte code and then execute it from the jar.

jar cfm build\jar\HelloWorld.jar myManifest -C build\classes .
java -jar build\jar\HelloWorld.jar

Using Ant to execute Selenium

Prerequisite requirement:
  1. Get a copy of TestNG from this site.Please note that I am not using the Eclipse plugin. The moment of this writingis 5.12.1 
  2. Get the ant from apache’s site. 
  3. Get the JDK from Sun’s site. 
  1. Add a new environment variable called JAVA_HOME under the System Variable group. Set the path to the JDK installationdirectory. Without this the compiler will complain that tools.jar not foundduring the Ant process. 
  2. Add the ant’s bin directory and jdk’sbin directory into Path environment variable under the System Variable group. 
The JAVA code:
  1. Create a JAVA project using Eclipse. 
  2. Add the testng-<version>.jar intobuild path and update all necessary info of the jar file (eg. SourceAttachment, JavaDoc, library location) for easier debugging purpose. 
  3. Create the source code below under thatsrc directory and name it as The code is actually copy fromTestNG’s site. 
    package package1;
    import org.testng.annotations.*;
    public class SimpleTest {
          public void setUp() {
             // code thatwill be invoked when this test is instantiated
          @Test(groups = { "fast" })
          public void aFastTest() {
             System.out.println("Fast test");
          @Test(groups = { "slow" })
          public void aSlowTest() {
             System.out.println("Slow test");
  5. Create the Ant file using code below:
  7. There are a couple of thing to take note here:
    • the Ant must be told that where the location of the testng<version>.jarfile and where are the binary file in pathelement location.
    • the destdir in javac indicate where the output of the binary class file shouldlocate after the compilation.
    • the correct location of the binary class must be set in classfileset otherwisean error complain that the build.xml not found.
  8. After this, the testng-output directory will be generated. Notice that thetestng-results.xml is created automatically for generating the testng-xsltreport purpose.