案例学 网页设计与网站建设,网站建设先做后,做赌场网站犯法么,洛南网站建设简单案例RunWith(Parameterized.class)public class ParameterTest {// 2.声明变量存放预期值和测试数据private String firstName;private String lastName;//3.声明一个返回值 为Collection的公共静态方法#xff0c;并使用Parameters进行修饰Parameterized.Parameterspubli…简单案例RunWith(Parameterized.class)public class ParameterTest {// 2.声明变量存放预期值和测试数据private String firstName;private String lastName;//3.声明一个返回值 为Collection的公共静态方法并使用Parameters进行修饰Parameterized.Parameterspublic static List param() {// 这里我给出两个测试用例return Arrays.asList(new Object[][]{{Mike, Black}, {Cilcln, Smith}});}//4.为测试类声明一个带有参数的公共构造函数并在其中为之声明变量赋值public ParameterTest(String firstName, String lastName) {this.firstName firstName;this.lastName lastName;}// 5. 进行测试发现它会将所有的测试用例测试一遍Testpublic void test() {String name firstName lastName;System.out.println(name);assertThat(Mike Black, is(name));}}参数化在 测试controller 中的应用RunWith(Parameterized.class)SpringBootTestpublic class LearnController14Test {Autowiredprivate WebApplicationContext wac;private MockMvc mvc;private MockHttpSession session;public Long id;public String title;public LearnController14Test(Long id, String title) {super();this.id id;this.title title;}/*** 这些参数都会测试一遍** return*/Parameterized.Parameterspublic static List data() {return Arrays.asList(new Object[][]{{999L, Black}, {997L, Smith}});}Beforepublic void setupMockMvc() throws Exception {//借助TestContextManager来实现上下文注入TestContextManager testContextManager new TestContextManager(getClass());testContextManager.prepareTestInstance(this);//初始化MockMvc对象mvc MockMvcBuilders.webAppContextSetup(wac).build();//构建sessionsession new MockHttpSession();User user new User(root, root);//拦截器那边会判断用户是否登录所以这里注入一个用户session.setAttribute(user, user);}/*** 获取教程测试用例* * get 请求** throws Exception*/Testpublic void qryLearn() throws Exception {mvc.perform(MockMvcRequestBuilders.get(/learn/resource/ id ?title title).contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8).session(session)).andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print());}}