JUnit for beginners.

JUnit is an open source framework designed for the purpose of writing and running tests in the Java programming language. JUnit, has been important in the evolution of test-driven development.
JUnit , making it possible to write and test source code quickly and easily. JUnit allows the developer to incrementally build test suites to measure progress and detect unintended side effects. Tests can be run continuously. Results are provided immediately. JUnit shows test progress in a bar that is normally green but turns red when a test fails. An ongoing list of unsuccessful tests appears in a space near the bottom of the display window. Multiple tests can be run concurrently. No subjective human judgments or interpretations of test results are required. The simplicity of JUnit makes it possible for the software developer to easily correct bugs as they are found.

Few reasons to know why to use?


1) JUnit tests allow you to write code faster while increasing quality.2) JUnit is elegantly simple and writing Junit tests is inexpensive. 3) JUnit tests check their own results and provide immediate feedback. 4) JUnit tests can be composed into a hierarchy of test suites. 5) It increase the stabilty of software.

You can download a latest version of JUnit.

STEP1 : Writing a Test Case


import junit.framework.TestCase;
public class ShoppingCartTest extends TestCase {
private ShoppingCart cart;
private Product book1;
protected void setUp() {
cart = new ShoppingCart();
book1 = new Product("Pragmatic Unit Testing", 29.95);
cart.addItem(book1);
}
protected void tearDown() {
// release objects under test here, if necessary
}
public void testEmpty() {
cart.empty();
assertEquals(0, cart.getItemCount());
}
public void testAddItem() {
Product book2 = new Product("Pragmatic Project Automation", 29.95);
cart.addItem(book2);
double expectedBalance = book1.getPrice() + book2.getPrice();
assertEquals(expectedBalance, cart.getBalance(), 0.0);
assertEquals(2, cart.getItemCount());
}
public void testRemoveItem() throws ProductNotFoundException {
cart.removeItem(book1);
assertEquals(0, cart.getItemCount());
}
public void testRemoveItemNotInCart() {
try {
Product book3 = new Product("Pragmatic Version Control", 29.95);
cart.removeItem(book3);
fail("Should raise a ProductNotFoundException");
} catch(ProductNotFoundException expected) {
}
}
}


STEP 2: Write a Test Suite

we'll write a test suite that includes several test cases. The test suite will allow us to run all of its test cases in one fell swoop.
To write a test suite, follow these steps:
Write a Java class that defines a static suite() factory method that creates a TestSuite containing all the tests.
Optionally define a main() method that runs the TestSuite in batch mode.
The following is an example test suite:


import junit.framework.Test;
import junit.framework.TestSuite;
public class EcommerceTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ShoppingCartTest.class);
suite.addTest(CreditCardTestSuite.suite());
return suite;
}
/**
* Runs the test suite using the textual runner.
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}



You can Download Complete source code.

I hope you got an idea how to run and why to use?

I will update it further very soon,....

Concept of SOA (Service Oriented Architecture)

This is a very good notes for Beginners to know about SOA.


SOA is not a technology or something you install. It is a concept, or rather an approach to modelling your system, and one that is different from the standard client/server model you may be used to. As opposed to large, proprietary applications that do everything, SOA is a design meant to try to integrate numerous and diverse software applications with common interfaces, in the name of code reuse/maintainability, and adaptibility. The notion of using a group of independent applications to accomplish a shared task is also sometimes referred to as grid computing.

Everyone knows that "Web Services" are one of the hottest things lately. An SOA is essentially a collection of such services, communicating with one another, generally through XML. (Of course I am over-simplifying things: SOA can involve any kind of self-contained service communicating in any way.)

SOA is not specific to any technology, indeed every "family" of technologies has its own SOA solution, and usually you can mix-and-match your own. However, open-source XML-based technologies such as BPEL, SOAP and WSDL are very commonly used.


I will update few more details related to SOA Soon..




What is Business Process Execution language (BPEL) ?

Why BPEL came into picture?

The purpose/idea behind almost new technology for application development is to provide an business application with less effort and also which can be easily adapted to changing nature of business processes without much effort.

Integrating a different applications is always a difficult task for various functional or technical realted reasons.eventhough JAVA has provided the excellent platform to develop such applications,as business application cannot be isolated.


So,now here SOA will come into picture,we can say integration challenges were resolved by Service Oriented Architecture (SOA) and web services technologies.Thus we can now access different functionalities of different legacy and new developed applications in a standard way (through web services). Such access to functionalities is important because typical companies have a large number of existing applications which have to be integrated.


Developing the web services and exposing the functionalities is not sufficient. We also need a way to compose these functionalities in the right order – a way to define business processes which will make use of the exposed functionalities. We would obviously prefer a relatively simple and straightforward way to define such processes, particularly because we know that business processes change often, therefore we would like to modify them easily.


This is where the BPEL (Business Process Execution Language for Web Services, also WS-BPEL or BPEL4WS) becomes important. BPEL allows composition of web services and is thus the top-down approach to SOA – the process oriented approach to SOA.