🐛 junit test

This commit is contained in:
毛毛虫 2022-01-20 15:29:28 +08:00
parent 1b2bf0fc03
commit 934b0efa4c
3 changed files with 23 additions and 8 deletions

10
pom.xml
View File

@ -296,6 +296,16 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<!--打包过程中跳过测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!--true跳过测试-->
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -1,14 +1,21 @@
package com.rymcu.forest.utils; package com.rymcu.forest.utils;
import org.junit.jupiter.api.Test; 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 org.springframework.util.DigestUtils;
import java.io.File; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.FileInputStream;
import java.io.InputStream;
// 仅运行指定类
@SpringBootTest(classes = TestFileMd5.class)
public class TestFileMd5 { public class TestFileMd5 {
@Value("classpath:1.txt")
private Resource testFile;
/** /**
* c6c26c7e8a5eb493b14e84bd91df60e3 * c6c26c7e8a5eb493b14e84bd91df60e3
* d41d8cd98f00b204e9800998ecf8427e * d41d8cd98f00b204e9800998ecf8427e
@ -17,10 +24,7 @@ public class TestFileMd5 {
*/ */
@Test @Test
public void test() throws Exception { public void test() throws Exception {
String pathName = "E:\\1.txt"; String md5 = DigestUtils.md5DigestAsHex(testFile.getInputStream());
InputStream inputStream = new FileInputStream(new File(pathName)); assertEquals("202cb962ac59075b964b07152d234b70", md5);
String md5 = DigestUtils.md5DigestAsHex((inputStream));
System.err.println(md5);
System.err.println(md5.length());
} }
} }

1
src/test/resources/1.txt Normal file
View File

@ -0,0 +1 @@
123