我正在使用Spring Boot Starter Test编写JUnit测试用例。我很想使用JunitParamrunner,它可以方便地传递文件以进行参数化测试。基本上,它逐行从文件中读取数据,并且每行都调用一个测试用例。问题是同时使用SpringJUnit4ClassRunner和JUnitParamsRunner都需要传递@RunWith。我不知道该怎么做。谁能提供一些线索。
我有 2 个带有参数的 pyTest 测试用例。我想使用两个参数按顺序运行它们,而不是使用所有可能的值运行第一个测试,然后开始第二个测试。
考虑下面的测试代码:
import pytest
@pytest.mark.parametrize("param1", [("A"), ("B")])
class TestClassTests:
def test_01_test(self, param1):
...
def test_02_test(self, param1):
...
Run Code Online (Sandbox Code Playgroud)
我得到的执行顺序是:
我想要的顺序是:
我必须读取一个CSV文件,并且每行中的每个组合都需要运行一些方法.我希望将每一行视为测试用例.是否可以将行作为参数发送 - pytest参数化我的测试用例?你能告诉我一些关于如何做到这一点的想法吗?
这是伪代码:
class test_mytest:
def test_rows:
for row in csvreader:
run_method(row)
for onecol in row:
run_method2(onecol)
Run Code Online (Sandbox Code Playgroud)
我试过阅读pytest文档,但对我来说并不清楚.
这是我正在做的使用generate_tests hook for row作为param.我想知道如何为内部for循环函数做同样的事情 - 这个内部循环也应该作为测试用例收集
def pytest_generate_tests(metafunc):
read_csvrows()
for funcargs in metafunc.cls.params[metafunc.function.__name__]:
# schedule a new test function run with applied **funcargs
metafunc.addcall(funcargs=funcargs)
class TestClass:
params = {
'test_rows': rows,
}
def test_rows:
run_method(row)
for onecol in row:
test_method2(onecol)
Run Code Online (Sandbox Code Playgroud)
现在,我需要为-for循环调用test_method2生成报告(它是csv文件每行中列中元素列表的参数化方法).Pytest也需要收集那些作为测试用例.
感谢你的帮助.谢谢
如何在Robot Framework中实现Gherkin数据表?
以下代码段应将两组(n,is_prime)参数传递给关键字,以便验证:
is_prime(5)=真
is_prime(6)=假
*** Test Cases ***
Function should verify prime number
Given I have a positive integer and is_prime() function
| n | is_prime |
| 5 | True |
| 6 | False |
When I check whether n is prime
Then is_prime() should verify this
Run Code Online (Sandbox Code Playgroud)
注意:这与场景大纲无关.我发现https://gist.github.com/Tset-Noitamotua/8f06bd490918a56b0485630016aef60b,并且可以使用机器人编写测试实例表.
这是一个Python函数,我用它来检查素数:
import math
def is_prime(num):
if num < 2:
return False
sqr = int(math.floor(math.sqrt(num)))
for i in range(2, sqr + 1):
if num …Run Code Online (Sandbox Code Playgroud) pytest ×2
python ×2
gherkin ×1
java ×1
junit4 ×1
junitparams ×1
pytest-order ×1
rows ×1
spring-boot ×1