Home >Java >JavaBase >How to test interface in java

How to test interface in java

尚
Original
2019-12-07 10:22:495137browse

How to test interface in java

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

How to test interface in java4. View the results

How to test interface in java

*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

How to test interface in javaHow to test interface in java2. Find the interface method to be tested in swagger

How to test interface in java3. Assignment test

How to test interface in java4. Check the test results

How to test interface in javaFor 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn