JUnit testing SSH JUnit can be used to test Java Web applications that use the SSH open-source framework. The DAO method and service-layer business logic method can be easily tested without relying on the framework.
To test the methods in Dao and service, you must first obtain the class instance. I think this is the most important thing. In SSH, Dao and service are both managed through spring, so they cannot get corresponding instances through new.
Use the following method to obtain Dao and service instances.
Public class xxxdaotest {private beanfactory; private xxxdao; @ beforepublic void getdao () {// you need to modify it as needed and find the configuration file in the classes path. Beanfactory = new classpathxmlapplicationcontext ("applicationcontext. XML "); xxxdao = (xxxdao) beanfactory. getbean ("xxxdao") ;}@ test public void testxxx () {// method of test. }
Of course, to use JUnit, you must add the corresponding JUnit and its dependent jar packages, which can be easily found on the Internet. If you don't want to use it yourself, many ides also provide support. For example, if you use myecplise, you can find the JUnit toolkit in build path-add libraries, and click it to select a version.