Hi all, We currently have openings for : • Senior Developers in Java and .net (4 -6 Yrs) • Java and .Net Architects(7+ yrs) • QA Architect.(7+yrs) We are looking at people who are hands on development and really passionate about coding and technology. If you have any friends or ex colleagues who would be interested in working with us kindly send me their resumes at rnikamATspiderlogicDOTcom
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.
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.
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.
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.
I'm trying to use the @Test(expected = RuntimeException.class) annotation in order to test for an expected exception. My code is as follows:
@Test(expected = RuntimeException.class)
public void testSaveThrowsRuntimeException(){
User user = domain.save(null);
}
and my save method simple like this :
public User save(User newUser) {
if(newUser == null) {
throw new RuntimeException();
}
//saving code goes here
}
after debugging the code I found that code throwing the exception as expected but its getting eaten somewhere in between in spring framework classes.
I tried the same with old way (try catch block) but still I am not able to catch that exception in test and test keeps throwing errors in runafter method of Junit :
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1031)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:504)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:277)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:170)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:344)
at org.springframework.test.context.junit4.SpringMethodRoadie.runAfters(SpringMethodRoadie.java:307)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:338)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.transaction.RollbackException
at org.objectweb.jotm.TransactionImpl.commit(TransactionImpl.java:245)
at org.objectweb.jotm.Current.commit(Current.java:488)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1028)
... 23 more
And I am sure this is because of that RuntimeException I am throwing in save but not able catch it or pass the test with expected clause.
anybody have any idea whats going wrong?
Thanks in advance,
Posted at
at
2:26 AM
on
Friday, July 24, 2009
by
Posted by
Ravindra Nikam
|
0
comments
|
Filed under:
Junit,
Spring
Firefox has a nice way to view files that are in both your memory and file cache. In the Address Bar, type – about:cache. This will take you to a page that allows you to view a summary of your browser cache and also will allow you to browse the files stored in the cache. Hit this link to change Firefox cache location.
Posted at
at
2:26 AM
on
Tuesday, July 24, 2007
by
Posted by
Ravindra Nikam
|
0
comments
|
Filed under:
cache,
Firefox