• 一起买beta版PHP单元测试


    一起买beta版PHP单元测试

    测试目的

    保证代码质量,对各个单元进行测试,可以有效地保证代码的可靠性,让模块在与别的模块整合时出现更少的错误。

    单元描述

    • 完成帖子接口

      ​ 将“正在进行”帖子状态更改为“已完成”。

    • 获取用户信息接口

      ​ 获得用户的个人信息。

    • 获取我的帖子接口

      ​ 获取用户帖子,包括“正在进行”、“已过期”、“已完成”。

    • 类型搜索接口

      ​ 返回指定类型的帖子。

    • 修改用户信息接口

      ​ 修改用户的个人信息,包括头像。

    • 管理员登录接口

      ​ 管理员登入系统。

    • 获得被举报帖子接口

      ​ 管理员获取被举报的帖子列表。

    • 举报帖子接口

      ​ 用户举报非法帖子。

    • 删除举报接口

      ​ 管理员删除用户的某个举报。

    • 更新帖子接口。

      ​ 用户修改帖子信息。

    • 过期设置接口

      把过期的帖子状态设置成已过期。

    • 获取用户相关帖子接口

      获取我的收藏和我的足迹。

    测试过程

    • 完成帖子测试
    use PHPUnitFrameworkTestCase;
    require_once 'FinishPosts.class.php';
    class FinishPostsTest extends TestCase
    {
        public function testFinishPosts()
        {
            $test = new FinishPosts();
            $test->finishTest(1);
        }
    }
    

    测试结果:

    • 获取用户信息测试
    use PHPUnitFrameworkTestCase;
    require_once 'GetUser.class.php';
    class GetUserTest extends TestCase
    {
        public function testGetUser()
        {
            $test = new GetUser();
            $test->getUserTest("linlin");
        }
    }
    

    测试结果:

    • 获取我的帖子测试
    use PHPUnitFrameworkTestCase;
    require_once 'MyPosts.class.php';
    class MyPostsTest extends TestCase
    {
        public function testMyPosts()
        {
            $test = new MyPosts();
            $test->myTest("linlin","正在进行");
        }
    }
    

    测试结果:

    • 类型帖子返回(类型搜索)测试
    use PHPUnitFrameworkTestCase;
    require_once 'TypeSearch.class.php';
    class TypeSearchTest extends TestCase
    {
        public function testTypeSearch()
        {
            $test = new TypeSearch();
            $test->typeTest("食品",0,5);
        }
    }
    

    测试结果:

    • 修改用户信息测试
    use PHPUnitFrameworkTestCase;
    require_once 'UpdateUser.class.php';
    class UpdateUserTest extends TestCase
    {
        public function testUpdateUser()
        {
            $test = new UpdateUser();
            $test->templateTest("linlin","boy","boss","1995-04-09","fzu","cs","","say:yes");
        }
    }
    

    测试结果:

    • 管理员登录测试
    use PHPUnitFrameworkTestCase;
    require_once 'AdminLogin.class.php';
    class AdminLoginTest extends TestCase
    {
        public function testAdminLogin()
        {
    //        $this->assertTrue(true);
            $test = new AdminLogin();
            $test->adminLoginTest("b","b");
        }
    }
    

    测试结果:

    • 获得被举报帖子测试
    use PHPUnitFrameworkTestCase;
    require_once 'GetReportedList.class.php';
    class GetReportedListTest extends TestCase
    {
        public function testGetReported()
        {
            //        $this->assertTrue(true);
            $test = new GetReportedList();
            $test->getListTest(1,3);
        }
    }
    

    测试结果:

    • 举报帖子测试
    use PHPUnitFrameworkTestCase;
    require_once 'ReportMessage.class.php';
    class ReportMessageTest extends TestCase
    {
        public function testReportMessage()
        {
            $test = new ReportMessge();
            $test->reportMessageTest(8);
        }
    }
    

    测试结果:

    • 删除举报测试
    use PHPUnitFrameworkTestCase;
    require_once 'ReportIgnore.class.php';
    class ReportIgnoreTest extends Testcase
    {
        public function testReportIgnore()
        {
            $test = new ReportIgnore();
            $test->ignoreTest(3);
        }
    }
    

    测试结果:

    • 更新帖子测试
    use PHPUnitFrameworkTestCase;
    require_once 'UpdatePosts.class.php';
    class UpdatePostsTest extends TestCase
    {
        public function testUpdatePosts()
        {
            $test = new UpdatePosts();
            $test->updateTest(2,"buysomething","","食品","bread",12.1,"piece",3,1,1,"willyoubuy","qq123321");
        }
    }
    

    测试结果:

    • 过期设置接口
    <?php
    use PHPUnitFrameworkTestCase;
    require_once 'OverTimeSet.class.php';
    class OverTimeSetTest extends TestCase
    {
        public function testOverTimeSet()
        {
            $test = new OverTimeSet();
            $test->OverTimeSetTest(1);
        }
    }
    

    测试结果:

    • 获取用户相关帖子测试
    use PHPUnitFrameworkTestCase;
    require_once 'GetStatePosts.class.php';
    class GetStatePostsTest extends TestCase
    {
        public function testGetStatePosts()
        {
            $test = new GetStatePosts();
            $test->getStatePosts("linlin",1);
        }
    }
    

    测试结果:

    结果统计

    十二个模块的测试,十二个模块无出现错误。

    质量评估

    总体上,模块并没有出错什么致命错误。

    测试总结

    更新帖子模块出现bug,是由于本地的操作系统为Windows7,和实际服务器的系统Ubuntu处理文件的方式不一致,因此,在图片文件的处理上,无法应用到本地的windows7系统,故有报错。这种情况下,就采用实际测试,测试结果该模块也可以正常使用。
    在测试过程中,遇到了个难以解决且最终没有解决的问题——dos窗口无法正常显示返回的中文字符!百度无果后就放弃了。实际测试,中文显示正常。
    觉得单元测试比起以前用postman之类工具测试的时候,觉得最大的益处就是在改以前代码的时候会感受的作用,而且还能指出哪里出了问题,很棒。

  • 相关阅读:
    oo第二次总结
    oo第一次总结
    OO最后一次博客儿
    OO作业总结第三弹
    OO作业总结第二弹
    初学面向对象
    hi🎈
    散列函数及其应用
    结对项目作业
    构建之法第四,第十四章读书有感 (另补第十七章)
  • 原文地址:https://www.cnblogs.com/wpqwpq/p/6172279.html
Copyright © 2020-2023  润新知