org.springframework.boot spring-boot-starter-test test
这里要单元测试的是打印出实体类的信息,而实体类的信息在.yml文件中 文件夹:
实体类 Person.java
@Component @ConfigurationProperties(prefix = "person") public class Person { private String name; private Integer age; private Boolean boss; private Date date; private Map maps; private List
其中有Dog的属性 所以 Dog.java
public class Dog { private String name; private String color;
@Override public String toString() { return "Dog{" + "name='" + name + '\'' + ", color='" + color + '\'' + '}'; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getColor() { return color; }
public void setColor(String color) { this.color = color; } }
@RunWith(SpringRunner.class)//用Spring的驱动器跑 @SpringBootTest//SpringBoot的单元测试 public class Test01 { @Autowired Person person; @Test public void test1(){ System.out.println(person); }