JUnit4[1] provides a set of annotations to help programmer write unit test with more easy way. you can find an introduction documents on the JUint offical web site.
Spring 2.5.5[2] is the latest Spring framework release. In this release, annotation programming support is also an important focus. Spring framework provides an enhanced
class named SpringJUnit4ClassRunner, which is a custom extension of JUnit4ClassRunner.
So, I use this new feature into my test cases and list as following.
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({})
@ContextConfiguration(locations={"/applicationContext.xml"})
public class OrderProcessDaoTest extends AbstractJUnit4SpringContextTests {
@Autowired
private OrderProcessDAO orderDao;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetNewOrders() {
if(orderDao == null)
fail("orderDao is null");
}
}
I also have an ant script to help me organize the build process.
The version of ant package is 1.7.1
Everything looks perfect, isn't it?
Well, the nightmare came to me when the first time I entered the "ant test-dao".
The ant output report a error said a method testAborted is not found.
then, another error came out said org.junit.internal.runners.JUnit4ClassRunner class not found.
I try to find the solution on the web.
[news.eclipse.platform] Ant junit 4 problem http://dev.eclipse.org/newslists/news.eclipse.platform/msg65786.html
Spring 2.5: Eclipse reports "JUnit4ClassRunner cannot be resolved" http://forum.springframework.org/showthread.php?t=47289
Named TestSuite gives error in JUnit_4.1 used w/Eclipse http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=68&t=001783
Problems running JUnit http://www.nabble.com/Problems-running-JUnit-td6915754.html
... you can find more just using "junit4 testAborted" as keyword to google.
Then I reviewed my enviroment, I found there exist several different version of junit.
In eclipse, junit 4.3 is in the feature plugin folder.
In ant's lib folder, there exists an junit 3.8.jar
In spring's lib folder, there exists an junit 4.4.jar.
In order to pass all the error found by the compiler, I choose spring's junit as my primary junit jar file.
After remove and redirect the classpath to junit.4.4 I solved this problem.
One strange thing I found is the junit.jar in spring framework seems inconsistency from JUnit offical site.
Once, I used the JUnit from spring everything is perfect.
Reference.
1.http://www.junit.org/
2.http://www.springframework.org/
2008年8月19日 星期二
JUnit4, Spring, and Ant integration
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言