What is CRUD?


The word 'CRUD' is a acronym in the computer world. It stands for Create, Read, Update and Delete. Sometimes R in 'CRUD' is used for the word Retrieve and D for Destroy.

Most of the time 'CRUD' is related to SQL database operations as follows.
  • C: INSERT
  • R: SELECT
  • U: UPDATE
  • D: DELETE

Liberty BASIC v5.0 for Linux Screenshots

Well, I promised to post some screenshots of Liberty BASIC v5.0 running on Linux, so here they are. Keep in mind that these are pre-alpha shots. Visit this link and click on the topic "Linux Screenshots"

http://libertybasic.conforums.com/index.cgi?board=lb5

-Carl

JUnit Getting Started

Main object:   Write a test case using JUnit as simple as possible.
Approach:   First write a class, then write the TestCase and the TestSuite.
Readers:   Should have some experience or knowledge in Java

by Kamal Mettananda

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. This is used by developers to implement unit tests in Java.

Why unit testing is needed?
With unit testing the end product is completely checked for the correcteness of the code. With the time, the set of tests grow and the ease of testing improves. One of the most important things is that developers can be confident on the code and less time needed for debugging.

What is JUnit?
JUnit is a Test framework. The features available are;
  • Assertion methods (test methods)
  • Running tests (TestRunner)
  • Aggregating tests (test suites)
  • Reporting results (text based and GUI based)
One factor that developers may worry is : the developers has to write tests.

Writing a JUnit Test in 5 minutes
First add the junit.jar file to the project (All the following classes are tested using junit-3.8.1.jar). Then write the follwing classes.

Writing JUnit class
  1. Define a subclass of TestCase.
  2. Override the setUp() & tearDown()methods.
  3. Define one or more public testXXX()methods
    all the methods starting with test will be run by the TestRunner
    • call the methods of tested object
    • check the expected results with assertXXX() methods
  4. Define a static suite() factory method
  5. Create a TestSuite class containing all the tests.
  6. Optionally define main() to run the TestCase in batch mode.

1. Write a class - Calc.java


package com.parcelhouse.myproj;

public class Calc {

     public Calc() {
          super();
     }
     public int add(int a, int b){
          // errorneous method
          return a+b+1;
     }
     public int multiply(int a, int b){
          return a*b;
     }
}


2. Write the test case - TestCalc.java (anyname can be used)


package test.com.parcelhouse.myproj;

import junit.framework.TestCase;
import com.parcelhouse.myproj.Calc;//testing class

public class CalcTest extends TestCase {

     Calc c = null;

     public CalcTest(String name) {
          super(name);
     }

     protected void setUp() throws Exception {
          super.setUp();
          c = new Calc();
     }

     /*
      * Test method for 'com.parcelhouse.myproj.Calc.add(int, int)'
      */
     public void testAdd() {
          int x = c.add(5,6);
          assertEquals(11, x);
     }

     /*
      * Test method for 'com.parcelhouse.myproj.Calc.multiply(int, int)'
      */
     public void testMultiply() {
          int x = c.multiply(5,6);
          assertEquals(30, x);
          }

     public static void main(String[] args) {
          junit.textui.TestRunner.run(CalcTest.class);
     }
}

  • Run test case using;
    >java CalcTest

  • The line junit.textui.TestRunner.run(CalcTest.class) is where the trick occurs. The TestRunner runs all the methods in the CalcTest class which has testXXX() signature using reflection.

  • c.add(5,6) line should return 11 if the method works fine. The return value is checked against the expected value in the assertXXX() method.
    As the method is errorneous, this throws junit.framework.AssertionFailedError.
    But the multiply() method works fine and causes no errors.

3. Write the Test Suite - TestSuite.java (anyname can be used)


package test.com.parcelhouse.myproj;

import junit.framework.Test;
import junit.framework.TestSuite;

public class Tests {
     public static void main(String[] args) {
          junit.textui.TestRunner.run(Tests.class);
          //junit.swingui.TestRunner.run(Tests.class);
          //junit.awtui.TestRunner.run(Tests.class);
     }
     public static Test suite() {
          TestSuite suite = new TestSuite("Test for test.com.parcelhouse.myproj");
          //$JUnit-BEGIN$
          suite.addTestSuite(CalcTest.class);
          suite.addTestSuite(ComputerTest.class);//another test case
          //$JUnit-END$
          return suite;
     }
}

  • Run Tests class with >java Tests
    all the testXXX() methods in all the testCases which are added to TestSuite inside suite() method are called.
  • junit.textui.TestRunner.run() gives results in text mode.
    But if junit.swingui.TestRunner.run() or junit.awtui.TestRunner.run() used, results come in UI mode.
  • Add the TestCase to the TestSuite inside suite() method, when ever a new TestCase is needed.

Oh! you are done. The complete TestSuite is completed.
One important thing to keep in mind, write code to do small operations as much as possible.

If you have any question or comment, just add as a comment and will be here to help you guys.

References:
www.junit.org
www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit.html
www.admc.com/blaine/howtos/junit/junit.html

LB5 update

I know a lot of people are eager to know how Liberty BASIC v5.0 is coming along.

First of all, please don't hold off purchasing Liberty BASIC because you think LB5 is about to be released. It won't be available until the end of 2006. Please go ahead and purchase LB v4.03. The upgrade to v5.0 will only be about $20.

Okay, so now some details. I am trying to wrap up an alpha release for testing by invitation only. The alpha will be Windows and maybe Linux. I'd like to release a Mac alpha also, but I'm having some issues that I'm seeking support for. Later this summer we will have beta versions which anyone can test, and these will probably all be Windows, Mac and Linux from the start.

A lot of energy has been going into the core language including user types, support for the new syntax for GUI controls, and graphics drawing.

In a few days I'll post some screenshots of how things are coming along for the general public, including an image demonstrating a grid control and the current (rough) state of the debugger.

I'm also going to blog soon about the new web BASIC Scott and I are working on. It is coming along nicely.

06:06:06 06/06/06



If you check the date and time today at 06:06:06 in the morning, you will see that it's full of sixes.

06:06:06 06/06/06

This will appear again only after 100 years. If you were living at that time (2106), better to add a comment saying this blog is 100 years older.

Related Posts:
01:02:03 04/05/06

Check out this stream