Unit testing ejb3 reference

To test ejb either we have to put test in ejb container or we can put container in test itself. following are few links to refer writing containers in test using openEJB.

How to unit test EJB
Build, deploy, and test EJB components in just a few seconds

Posted at at 6:35 AM on Thursday, August 20, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: ,

Using regular expresions(regex, regexp)

Regular Expression Basic Syntax Reference

Posted at at 4:24 AM on Sunday, August 9, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under:

TestNG and JUnit in one project with maven surefire

This can be achieved using options such as using different profiles for both and another is by setting JUnit property true for surefire plug in.

Run "mvn test". Only the TestNG test will run since as soon as the maven founds the TestNG dependency in main profile it executes TestNG tests only. If you modify the pom to set the property "junit=true", only the JUnit test will run.


org.apache.maven.plugins
maven-surefire-plugin
2.4.2



junit
true



  

But personally my experience is it wont works with JUnit4.

Since it is the TestNG dependency that triggers surefire to use the TestNG runner to execute tests, We've to move this dependency out of the main project scope. In order to compile and run all JUnit tests, and needs to exclude the TestNG tests from the compiler and surefire plugins.

Then in a profile, add TestNG dependency and adjust the compiler and surefire plugins to include the TestNG tests but don't forget and override exclude if you are inheriting from main profile.


test



org.apache.maven.plugins
maven-compiler-plugin
2.0.2

1.5
1.5

**/testNGTests/**.java








testNG



org.apache.maven.plugins
maven-compiler-plugin
2.0.2

1.5
1.5

**/junitTests/**.java







org.testng
testng
5.8
test
jdk15





To run JUnit tests I use: mvn test
To run testNG tests I use: mvn test -P testNG

Posted at at 3:36 AM on Saturday, August 8, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: , ,

Java Unit Testing : JUnit Vs TestNG

Just wanted share thought with you all about two very well accepted unit testing frameworks (JUnit and TestNG) in Java world, off course there are lots of differences in these two but I wanted to share the one I encountered today. I found built-in Parameterized runner is quite crude in Junit4 as compare to TestNG (I know each framework has its strengths but still).In JUnit we are not allowed to write more than one data providing methods with annotation @parameters . I encountered this problem while testing the valid and invalid behavior for functionality in same test class. So the first public, static annotated javascript:void(0)method that it finds will be used, but it may find them in any order. This causes us to write different classes unnecessarily. However TestNG provides clean way to provide different kind of data providers for each and every method. So we can test the same unit of code with valid and invalid way in same test class putting the valid/invalid data separately.
Examples:
JUnit4:

Here we can not specify value for @parameters so it will be only and even if we have multiple methods the runner will return one of them. So we can provide only one kind of data Valid or invalid.
TestNG:

@Test(dataProvider = "Data-Provider-Function")
public void parameterIntTest(Class clzz, String[] number) {
System.out.println("Parameterized Number is : " + number[0]);
System.out.println("Parameterized Number is : " + number[1]);
}

//This function will provide the patameter data or we can use xml as well
@DataProvider(name = "Data-Provider-Function")
public Object[][] parameterIntTestProvider() {
return new Object[][]{
{Vector.class, new String[] {"java.util.AbstractList", "java.util.AbstractCollection"}},
{String.class, new String[] {"1", "2"}},
{Integer.class, new String[] {"1", "2"}}
};
}


Here in this case we can create as many data provider functions as we can and associate with appropriate method using @dataprovider.

Posted at at 3:54 AM on Saturday, August 1, 2009 by Posted by Ravindra Nikam | 2 comments   | Filed under: , ,