Nowadays, most of the Java projects are separated from the front and back ends. In the past, when they were not separated, when testing the interface they made, they would directly start the interface to enter data, break points, etc. for debugging. Then Now that the front-end and back-end are separated, how do you test your own interface after writing the back-end interface, right?
*test class - local test
The first method is to write a test class, call the Facade interface, and get a value from the database, in the test class Assign an actual parameter to the formal parameter of the interface, and then run or breakpoint debugging. The detailed operations are as follows:
1. Write the test class
2. Get the value and assign it
/** * 根据教师id查询老师所教公选课和非公选课的课程信息 */ @Test public void queryTeachercourseInfo() { //把从数据库里取得值赋给接口的形参 String teacherId = "ShfxVkbMvX9ZW5P7n4WnmN"; //调Facade接口 List<QueryMyCourseModel> list = teacherCourseFacade.queryTeachercourseInfo(teacherId); //循环打印获取的id for(QueryMyCourseModel queryMyCoureseModel : list){ System.out.println(queryMyCoureseModel.getTeacherId()); } }
3. Start the test
4. View the results
*swagger——server test
The second method is to use swagger For testing, if you want to use swagger to test, you must remember to submit the code before testing, and then build it. Otherwise, the method you wrote may not be remote. The detailed operations are as follows:
1. Start service and web
2. Find the interface method to be tested in swagger
3. Assignment test
4. Check the test results
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of How to test interface in java. For more information, please follow other related articles on the PHP Chinese website!