refactor(Test): 将测试类中随机字符串的生成提到基类中

This commit is contained in:
禾几海
2020-08-15 12:16:39 +08:00
parent bdcfaef5f8
commit 94c9fc1c46
3 changed files with 5 additions and 8 deletions

View File

@@ -6,7 +6,6 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.*;
@@ -37,7 +36,7 @@ public class ArticleMapperTest extends BaseTest {
@Test
public void update() {
Article article = generateArticle().getArticle();
String randomText = UUID.randomUUID().toString();
String randomText = randomStr();
// 此字段不会通过insert被写入数据库而是使用插入数据的默认值 数据库中该字段默认为true
article.setOpen(true);
@@ -117,7 +116,7 @@ public class ArticleMapperTest extends BaseTest {
public void existsByTitle() {
Article article = generateArticle().getArticle();
assertTrue(articleMapper.existsByTitle(article.getTitle()));
assertFalse(articleMapper.existsByTitle(UUID.randomUUID().toString()));
assertFalse(articleMapper.existsByTitle(randomStr()));
}
@Test
@@ -196,7 +195,7 @@ public class ArticleMapperTest extends BaseTest {
}
private ArticleTag generateArticle() {
String randomText = UUID.randomUUID().toString();
String randomText = randomStr();
Article article = new Article();
Category category = new Category();

View File

@@ -5,9 +5,8 @@ import cn.celess.blog.entity.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.*;
@@ -111,7 +110,7 @@ public class ArticleTagMapperTest extends BaseTest {
}
private ArticleTag generateArticle() {
String randomText = UUID.randomUUID().toString();
String randomText = randomStr();
Article article = new Article();
Category category = new Category();

View File

@@ -5,7 +5,6 @@ import cn.celess.blog.entity.Category;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;