Announcement Announcement Module
Collapse
No announcement yet.
How to do Junit testing using spring . Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to do Junit testing using spring .

    Hi,

    I am new to spring framework . I am trying to write a simple junit test case for my DAO layer and it result in the follwoing error.

    ERROR:
    ================================================== =================
    java.lang.IllegalArgumentException: No SqlMapClient specified
    at org.springframework.util.Assert.notNull(Assert.jav a:91)
    at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMapClientTemplate.java:139)
    at org.springframework.orm.ibatis.SqlMapClientTemplat e.insert(SqlMapClientTemplate.java:293)
    at com.ompay.om.dao.ibatis.SqlMapMemberDao.insertMemb er(SqlMapMemberDao.java:78)
    at Sample.testMemberInsert(Sample.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154 )
    at junit.framework.TestCase.runBare(TestCase.java:127 )
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:478)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:344)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)

    ================================================== ===============

    Sample Test case :
    ==============

    import junit.framework.TestCase;

    import com.ompay.om.dao.ibatis.SqlMapMemberDao;
    import com.ompay.om.domain.Member;

    public class Sample extends TestCase {

    public Sample(String name) {
    super(name);
    }

    public void testMemberInsert() throws Exception {

    Member member = new Member();

    member.setType("test_type");
    member.setStart_date("10/10/2006");

    SqlMapMemberDao memberDAO= new SqlMapMemberDao();
    memberDAO.insertMember(member);

    }//End of testMemberInsert()

    protected void setUp() throws Exception {
    super.setUp();
    }

    protected void tearDown() throws Exception {
    super.tearDown();
    }

    }//End of Sample class

    ================================================== ===============
    insert method of SqlMapMemberDao:
    ============================
    public class SqlMapMemberDao extends SqlMapClientDaoSupport implements MemberDao {
    public long insertMember(Member member) throws DataAccessException {

    getSqlMapClientTemplate().insert("insertRetailerDi scount", member);
    )
    )

    ================================================== ===============

    Here is my understanding of the problem:

    1. The SqlMapMemberDao class is making use of get SQLMapClientDaoSupport class and its its not initilized.
    2.I guess we have to load the mapping files used for context and the sql-mapping files used for query.if so please let me know how to load these conf files.

    It would be great if you could provide we a working sample test case.My intent is just to write test cases for all my methods in DAO later.

    Thanks in advance for your help.

    -Rajesh

  • #2
    Look at the Testing chapter in the Spring Reference Manual. The org.springframework.test package (shipped in spring-mock.jar) is designed for integration testing that loads Spring configuration and also allows for data access in a transactional environment, with automatic rollback.

    Comment

    Working...
    X