spring boot 测试简单写法

用testNG测试,可以做简单的并发测试


import org.testng.annotations.Test;

@SpringBootTest(classes = MyServiceTest.TestApplication.class, properties = {"spring.profiles.active=dev"})
public class MyServiceTest extends AbstractTransactionalTestNGSpringContextTests {

	@Test(invocationCount = 10,threadPoolSize = 5)
	public void updateProcess() throws Exception {

		System.out.println("test");

	}

	@SpringBootApplication
	@ComponentScan(value = {"com.my.foo"})
	public static class TestApplication {
	}
}

testNG 默认是不提交数据库的,所以想要提交到数据库得用

@Rollback(false)

普通测试

@SpringBootTest(classes = SensiTest.TestApplication.class )
@ActiveProfiles("dev") 
@RunWith(SpringRunner.class)
public class SensiTest {
 //testing...

	@SpringBootApplication
	@ComponentScan(value = {"com.my.foo"})
	public static class TestApplication {
	}
}
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注