From 934b0efa4c12389eb0cf06db272b1083c1e61676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AF=9B=E6=AF=9B=E8=99=AB?= <1421374934@qq.com> Date: Thu, 20 Jan 2022 15:29:28 +0800 Subject: [PATCH] :bug: junit test --- pom.xml | 10 ++++++++++ .../com/rymcu/forest/utils/TestFileMd5.java | 20 +++++++++++-------- src/test/resources/1.txt | 1 + 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/1.txt diff --git a/pom.xml b/pom.xml index 2d18bc8..6596ea2 100644 --- a/pom.xml +++ b/pom.xml @@ -296,6 +296,16 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + true + + org.springframework.boot spring-boot-maven-plugin diff --git a/src/test/java/com/rymcu/forest/utils/TestFileMd5.java b/src/test/java/com/rymcu/forest/utils/TestFileMd5.java index 5a5f2be..17fe9f0 100644 --- a/src/test/java/com/rymcu/forest/utils/TestFileMd5.java +++ b/src/test/java/com/rymcu/forest/utils/TestFileMd5.java @@ -1,14 +1,21 @@ package com.rymcu.forest.utils; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.io.Resource; import org.springframework.util.DigestUtils; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; +import static org.junit.jupiter.api.Assertions.assertEquals; +// 仅运行指定类 +@SpringBootTest(classes = TestFileMd5.class) public class TestFileMd5 { + + @Value("classpath:1.txt") + private Resource testFile; + /** * c6c26c7e8a5eb493b14e84bd91df60e3 * d41d8cd98f00b204e9800998ecf8427e @@ -17,10 +24,7 @@ public class TestFileMd5 { */ @Test public void test() throws Exception { - String pathName = "E:\\1.txt"; - InputStream inputStream = new FileInputStream(new File(pathName)); - String md5 = DigestUtils.md5DigestAsHex((inputStream)); - System.err.println(md5); - System.err.println(md5.length()); + String md5 = DigestUtils.md5DigestAsHex(testFile.getInputStream()); + assertEquals("202cb962ac59075b964b07152d234b70", md5); } } diff --git a/src/test/resources/1.txt b/src/test/resources/1.txt new file mode 100644 index 0000000..d800886 --- /dev/null +++ b/src/test/resources/1.txt @@ -0,0 +1 @@ +123 \ No newline at end of file