1、引入包
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
2、测试代码示例
import org.junit.jupiter.api.Test;
import java.util.Formatter;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertEquals;
class FormatterTest {
@Test
void errFormatterTest(){
String t1 = "this is %s bucket,its code is %s";
String t2 = "that is old bucket";
//如果存在预处理格式的字符串就做相应的替换
Formatter formatter1 = new Formatter();
formatter1.format(Locale.getDefault(Locale.Category.FORMAT),
t1, "wfwf","3");
assertEquals(formatter1.toString(),"this is wfwf bucket,its code is 3");
Formatter formatter2 = new Formatter();
formatter2.format(Locale.getDefault(Locale.Category.FORMAT),
t2, "wfwf");
assertEquals(formatter2.toString(),"that is old bucket");
}
}