我尝试使用Spring注释@IntegrationTest
在随机端口上运行集成测试。但是,我一直都在8080。有什么想法吗?
代码I'使用:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;
import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseSetup;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class })
@SpringApplicationConfiguration(classes = {FooConfig.class})
@DatabaseSetup("/db/Foo.xml")
@IntegrationTest("server.port:0")
@Transactional
public class Foo{
@Value("${local.server.port}")
private int port;
@Test
public void test() {
System.out.println(port);
}
}