mock

package repository;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import config.Config;

@EnableAutoConfiguration
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = Config.class)
@PropertySource("classpath:application.properties")
@ConfigurationProperties("spring.datasource")
//@Import (Config.class)
public class EmployeeRepositoryTest {
    @Autowired
    Environment env;

    @Autowired
    EmployeeRepository repository;

    @Test
    public void u_1_get() {
        String url = env.getProperty("spring.datasource.url");
        System.out.println("------------------------------------------"+url);
        String expectRet = "Jane:123";
        System.out.println("----------result:"+repository.getName("20190121"));
        assertEquals(repository.getName("123"), expectRet);

    }
}
 

你可能感兴趣的:(junit,spring,java)