How to load test data from test/fixtures yml file in Rails units
Date : March 29 2020, 07:55 AM
it helps some times How to load test data from test/fixtures yml file in Rails units , fixtures/xxxs.yml - one:
clm1: test
clm2: test
test "load_yml_obj" do
assert_not_nil xxxs(:one)
end
|
play auto-test selenium test failed, no test-result TEST-{testname}.xml file generated
Date : March 29 2020, 07:55 AM
|
how to run multiple test cases in junit or testng with different set of test data from csv file
Date : March 29 2020, 07:55 AM
Hope that helps Well, there are parameterized tests... You could use them. @RunWith(Parameterized.class)
public class YourTest {
@Parameters
public static Collection<Object[]> data() {
try( FileReader read = new FileReader(fileName)) {
CSVReader csvReader = new CSVReader(reader);
List<CSVRecord> records = ... read data;
Object[][] parameters = new Object[records.length][1];
for(int i=0; i<records.length; i++) {
parameters[i][0] = records.get(i);
}
return parameters;
}
}
private CsvRecord record; // [0] from the array goes here
public YourTest (CsvRecord record) {
this.record = record;
}
@Test
public void test() {
...do something with the record
}
}
|
Parametrize the test based on the list test-data from a json file
Date : March 29 2020, 07:55 AM
hope this fix your issue I would handle the special parametrization case in pytest_generate_tests hook: # conftest.py
import json
import pathlib
import pytest
@pytest.fixture(scope="class")
def test_config(request):
f = pathlib.Path(request.node.fspath.strpath)
config = f.with_name("config.json")
with config.open() as fd:
testdata = json.loads(fd.read())
yield testdata
@pytest.fixture(scope="function")
def config_data(request, test_config):
testdata = test_config
test = request.function.__name__
if test in testdata:
test_args = testdata[test]
yield test_args
else:
yield {}
def pytest_generate_tests(metafunc):
if 'config_data' not in metafunc.fixturenames:
return
config = pathlib.Path(metafunc.module.__file__).with_name('config.json')
testdata = json.loads(config.read_text())
param = testdata.get(metafunc.function.__name__, None)
if isinstance(param, list):
metafunc.parametrize('config_data', param)
# testcases/project_1/config.json
{
"test_one": [1, 2, 3],
"test_two": "split"
}
# testcases/project_1/test_suite_1.py
def test_one(config_data):
assert config_data >= 0
def test_two(config_data):
assert config_data == 'split'
# testcases/project_2/config.json
{
"test_three": {"three": 3},
"test_four": {"four": 4}
}
# testcases/project_2/test_suite_2.py
def test_three(config_data):
assert config_data['three'] == 3
def test_four(config_data):
assert config_data['four'] == 4
$ pytest -vs
============================== test session starts ================================
platform linux -- Python 3.6.5, pytest-3.4.1, py-1.5.3, pluggy-0.6.0 --
/data/gentoo64/usr/bin/python3.6
cachedir: .pytest_cache
rootdir: /data/gentoo64/home/u0_a82/projects/stackoverflow/so-50815777, inifile:
plugins: mock-1.6.3, cov-2.5.1
collected 6 items
testcases/project_1/test_suite_1.py::test_one[1] PASSED
testcases/project_1/test_suite_1.py::test_one[2] PASSED
testcases/project_1/test_suite_1.py::test_one[3] PASSED
testcases/project_1/test_suite_1.py::test_two PASSED
testcases/project_2/test_suite_2.py::test_three PASSED
testcases/project_2/test_suite_2.py::test_four PASSED
============================ 6 passed in 0.12 seconds =============================
|
Unit testing Scala.js: Read test data from file residing in `test/resources`
Tag : scala , By : fedorafennec
Date : March 29 2020, 07:55 AM
|