HttpRunner3的用例是怎么运行起来的
在PyCharm中打开examples/httpbin/basic_test.py:
在PyCharm中打开examples/httpbin/basic_test.py:
本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 Servlet版本 Oracle将Java EE(Java SE还自己保留)交给开源组织,Eclipse基金会接手。但Oracle不允许开源组织使用Java名号,所以Jakarta EE名称于2018.02.26应运而生。 正是因为组织变化,Servlet被割裂为了2个版本,javax.servlet和jakarta.servlet。 javax.servlet已经停止维护,但它仍然是一个非常有用和重要的技术,特别是在许多现有项目中,学习和使用它将为你提供坚实的Web开发基础。 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> 如果希望使用Jakarta EE 9或更高版本的Servlet API,则需要切换到javax.servlet。 <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency> 本文将基于javax.servlet来介绍Servlet,从Usages来看,它仍然是使用最广泛的。 Servlet API Servlet API主要有2个包,javax.servlet包含了servlet和web container使用的接口和类。javax.servlet.http包含了http相关的接口和类。 javax.servlet接口列表: Servlet ServletRequest ServletResponse RequestDispatcher ServletConfig ServletContext SingleThreadModel Filter FilterConfig FilterChain ServletRequestListener ServletRequestAttributeListener ServletContextListener ServletContextAttributeListener javax.servlet类列表: GenericServlet ServletInputStream ServletOutputStream ServletRequestWrapper ServletResponseWrapper ServletRequestEvent ServletContextEvent ServletRequestAttributeEvent ServletContextAttributeEvent ServletException UnavailableException javax.servlet.http接口列表: HttpServletRequest HttpServletResponse HttpSession HttpSessionListener HttpSessionAttributeListener HttpSessionBindingListener HttpSessionActivationListener HttpSessionContext (deprecated now) javax.servlet.http类列表: ...
JMeter的界面虽然不华丽,但是使用起来还是很便利。本文将基于英文版界面对整个可视区域进行介绍,如果想看中文版,请在菜单栏点击Choose Language切换:
JUnit5的测试不是通过名称,而是通过注解来标识的。
本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 系统架构 前端、后端、pytest均以Docker容器运行服务,单独的容器化执行引擎,项目环境隔离,即用即取,用完即弃,简单,高效。 前端容器:页面交互,请求后端,展示HTML报告 后端容器:接收前端请求,启动任务,构建镜像,触发运行pytest,挂载HTML报告 pytest容器:拉取项目代码,指定目录执行,生成HTML报告 说明:构建镜像目前是在宿主机启动后端服务来执行docker命令的,暂未支持Kubernetes编排。宿主机安装了Docker,启动服务后,可以执行docker命令。如果采用容器部署后端,容器里面不包含Docker,无法构建,个人想法是可以借助K8S来编排,当前版本还未实现 系统流程 支持2种运行模式配置:容器和本地。 容器模式:判断是否支持docker,如果支持,构建pytest镜像,在构建时,通过git拉取项目代码,再运行容器,按照指定目录执行pytest,生成测试报告,并将报告文件挂载到后端。如果不支持,降级为本地运行。 本地模式:模拟容器行为,在本地目录拉取代码,执行pytest,生成测试报告。 效果展示 任务管理: 容器模式: 本地模式: 平台大改造 pytestx平台更轻、更薄,移除了用例管理、任务关联用例相关功能代码,只保留真正的任务调度功能,backend的requirements.txt解耦,只保留后端依赖,pytest相关依赖转移到tep-project。 那如何管理用例呢?约定大于配置,我们约定pytest项目已经通过目录维护好了一个稳定的自动化用例集,也就是说需要通过平台任务调度的用例,都统一存放在目录X下,这些用例基本不需要维护,可以每日稳定执行,然后将目录X配置到平台任务信息中,按指定目录执行用例集。对于那些不够稳定的用例,就不能放到目录X下,需要调试好以后再纳入。 为什么不用marker?pytest的marker确实可以给测试用例打标记,也有人是手动建立任务和用例进行映射,这些方式都不如维护一个稳定的自动化用例集方便,在我们公司平台上,也是维护用例集,作为基础用例集。使用pytest项目同理。 核心代码 一键部署 #!/bin/bash PkgName='backend' Dockerfile='./deploy/Dockerfile.backend' DockerContext=./ echo "Start build image..." docker build -f $Dockerfile -t $PkgName $DockerContext if [ $? -eq 0 ] then echo "Build docker image success" echo "Start run image..." docker run -p 8000:80 $PkgName else echo "Build docker image failed" fi FROM python:3.8 ENV LANG C.UTF-8 ENV TZ=Asia/Shanghai RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone WORKDIR /app COPY ./backend . RUN pip install -r ./requirements.txt -i \ https://pypi.tuna.tsinghua.edu.cn/simple \ --default-timeout=3000 CMD ["python", "./manage.py", "runserver", "0.0.0.0:80"] 数据库表 ...
本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 fixture是什么 看看源码 def fixture( callable_or_scope=None, *args, scope="function", params=None, autouse=False, ids=None, name=None ): """Decorator to mark a fixture factory function. This decorator can be used, with or without parameters, to define a fixture function. The name of the fixture function can later be referenced to cause its invocation ahead of running tests: test modules or classes can use the ``pytest.mark.usefixtures(fixturename)`` marker. Test functions can directly use fixture names as input arguments in which case the fixture instance returned from the fixture function will be injected. Fixtures can provide their values to test functions using ``return`` or ``yield`` statements. When using ``yield`` the code block after the ``yield`` statement is executed as teardown code regardless of the test outcome, and must yield exactly once. :arg scope: the scope for which this fixture is shared, one of ``"function"`` (default), ``"class"``, ``"module"``, ``"package"`` or ``"session"`` (``"package"`` is considered **experimental** at this time). This parameter may also be a callable which receives ``(fixture_name, config)`` as parameters, and must return a ``str`` with one of the values mentioned above. See :ref:`dynamic scope` in the docs for more information. :arg params: an optional list of parameters which will cause multiple invocations of the fixture function and all of the tests using it. The current parameter is available in ``request.param``. :arg autouse: if True, the fixture func is activated for all tests that can see it. If False (the default) then an explicit reference is needed to activate the fixture. :arg ids: list of string ids each corresponding to the params so that they are part of the test id. If no ids are provided they will be generated automatically from the params. :arg name: the name of the fixture. This defaults to the name of the decorated function. If a fixture is used in the same module in which it is defined, the function name of the fixture will be shadowed by the function arg that requests the fixture; one way to resolve this is to name the decorated function ``fixture_<fixturename>`` and then use ``@pytest.fixture(name='<fixturename>')``. """ if params is not None: params = list(params) fixture_function, arguments = _parse_fixture_args( callable_or_scope, *args, scope=scope, params=params, autouse=autouse, ids=ids, name=name, ) scope = arguments.get("scope") params = arguments.get("params") autouse = arguments.get("autouse") ids = arguments.get("ids") name = arguments.get("name") if fixture_function and params is None and autouse is False: # direct decoration return FixtureFunctionMarker(scope, params, autouse, name=name)( fixture_function ) return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name) 总结一下 ...
本文是一篇过渡,在进行用例管理模块开发之前,有必要把入门篇开发完成的代码部署到Linux系统Docker中,把部署流程走一遍,这个过程对后端设计有决定性影响。
基本功能:
JaCoCo全称是Java Code Coverage,Java代码覆盖率,广泛运用于各种测试平台对Java代码的全量覆盖率和增量覆盖率进行统计,分析代码行差异,度量单元测试效果。Jacoco也是精准测试的技术实现手段之一。
FastAPI的路径操作函数,可以使用async def定义: