|
Test
How to create a Test to submit an issue.
We appreciate that uses fill issues with bug reports, feature suggestions or new ideas. This is in fact the basis of the evoution of MyBatis. To facilitate the adoption of your idea or to demonstrate a failure we would like to ask you to provide unit tests. A test will make life easier for everyone, it will be easier for you to explain the idea or problem and for team members to understand it and take an action. Base Unit TestEven if you are not familiarized with unit testing you will see that coding a unit test is an easy task. MyBatis provides a sample base test that serves as a basis for your test. Check it out from here http://mybatis.googlecode.com/svn/trunk/src/test/java/org/apache/ibatis/submitted/basetest/ This test is quite simple, it is composed by the following files:
This is how it works.
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/basetest/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/basetest/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setErrorLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();@Test
public void shouldGetAUser() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Mapper mapper = sqlSession.getMapper(Mapper.class);
User user = mapper.getUser(1);
Assert.assertEquals("User1", user.getName());
} finally {
sqlSession.close();
}
}Code your own TestTaking base test as a basis these are the modifications you should do to build your own test:
| |