Skip to content

Commit

Permalink
更新测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
happyxiaofan committed Sep 14, 2017
1 parent 3eab491 commit 50b5525
Showing 1 changed file with 26 additions and 48 deletions.
Expand Up @@ -9,9 +9,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;
Expand All @@ -20,7 +18,6 @@

@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class ApplicationTests {

@Autowired
Expand All @@ -41,10 +38,10 @@ public void setup() {
" UNIQUE KEY `id_UNIQUE` (`id`)\n" +
") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='用户信息表';\n";
jdbcTemplate.update(sql);
userMapper.deleteByExample(new UserExample());
}

@Test
public void insertTest() {
public void testUp() {
User user = new User();
user.setUserId(1L);
user.setUserName("springboot");
Expand All @@ -53,79 +50,60 @@ public void insertTest() {
assertTrue(userMapper.insertSelective(user) > 0);
}

@Test
public void insertTest2() {
User user = new User();
user.setUserId(2L);
user.setUserName("springboot2");
user.setAge(1);
user.setBirth(new Date());
assertTrue(userMapper.insert(user) > 0);
public void tearDown() {
UserExample example = new UserExample();
example.createCriteria().andUserIdEqualTo(1L);
assertTrue(userMapper.deleteByExample(example) > 0);
}

@Test
public void queryTest() {
testUp();
List<User> users = userMapper.selectByExample(new UserExample());
if (!CollectionUtils.isEmpty(users)) {
assertTrue(userMapper.selectByPrimaryKey(users.get(0).getId()).getAge() == 1);
}
assertTrue(userMapper.selectByPrimaryKey(users.get(0).getId()).getAge() == 1);
tearDown();
}

@Test
public void countTest() {
assertTrue(userMapper.countByExample(new UserExample()) > 0);
testUp();
assertTrue(userMapper.countByExample(new UserExample()) >= 0);
tearDown();
}

@Test
public void updateTest() {
testUp();
List<User> users = userMapper.selectByExample(new UserExample());
if (!CollectionUtils.isEmpty(users)) {
User user = users.get(users.size() - 1);
user.setUserName("updateTest");
assertTrue(userMapper.updateByPrimaryKeySelective(user) > 0);
}
User user = users.get(users.size() - 1);
user.setUserName("updateTest");
assertTrue(userMapper.updateByPrimaryKeySelective(user) > 0);
tearDown();
}

@Test
public void updateTest2() {
testUp();
List<User> users = userMapper.selectByExample(new UserExample());
if (!CollectionUtils.isEmpty(users)) {
User user = users.get(users.size() - 1);
user.setUserName("updateTest2");
assertTrue(userMapper.updateByPrimaryKey(user) > 0);
}
}

@Test
public void deleteTest() {
List<User> users = userMapper.selectByExample(new UserExample());
if (!CollectionUtils.isEmpty(users)) {
User user = users.get(0);
assertTrue(userMapper.deleteByPrimaryKey(user.getId()) > 0);
}
}

@Test
public void deleteTest2() {
List<User> users = userMapper.selectByExample(new UserExample());
if (!CollectionUtils.isEmpty(users)) {
User user = users.get(0);
UserExample example = new UserExample();
example.createCriteria().andIdEqualTo(user.getId());
assertTrue(userMapper.deleteByExample(example) > 0);
}
User user = users.get(users.size() - 1);
user.setUserName("updateTest2");
assertTrue(userMapper.updateByPrimaryKey(user) > 0);
tearDown();
}

@Test
public void distinctOrTest() {
testUp();
UserExample example = new UserExample();
example.setDistinct(true);
UserExample.Criteria criteria = example.createCriteria();
criteria.andAgeIsNotNull();
UserExample.Criteria or = example.or();
or.andIdIsNotNull();
example.setOrderByClause("id asc");
userMapper.selectByExample(example);
List<User> users = userMapper.selectByExample(example);
assertTrue(users.size() > 0);
tearDown();
}

}

1 comment on commit 50b5525

@Baray-Allen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Please sign in to comment.