springboot_单元测试

pom.xml

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <!--springboot会自动维护版本-->
        </dependency>

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
可以引用容器中的bean

会自动加载测试resources中的yml

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class JsonConvert {
	@Autowired
	private ObjectMapper objectMapper;


	@Test
	public void test() throws JsonProcessingException {
		TUserJwtshiro tUserJwtshiro = new TUserJwtshiro();
		tUserJwtshiro.setId(1L);
		tUserJwtshiro.setName("马庆斌");
		tUserJwtshiro.setUsername("");
		tUserJwtshiro.setPassword("password");
		tUserJwtshiro.setSalt("salt");
		tUserJwtshiro.setIslocked(true);
		tUserJwtshiro.setCreateTime(new Date());
		tUserJwtshiro.setUpdateTime(new Date());
		String jsonStr = objectMapper.writeValueAsString(tUserJwtshiro);
		System.out.println("========"+jsonStr);
	}
}

猜你喜欢

转载自blog.csdn.net/maqingbin8888/article/details/83114078