128 questions
0
votes
1
answer
86
views
How can I get the actual type from a generic type parameter
Say, I have an abstract class for testing.
abstract class BaseEntity<SELF extends BaseEntity<SELF>> {
}
I declared an abstract test class for testing subclasses of the BaseEntity.
...
0
votes
1
answer
196
views
Repeated parameterized test with JUnit 5 / Jupiter
I want to repeatedly execute the following test class:
class Test {
static Foo foo;
@BeforeAll
static void setUpAll() {
foo = generateRandomFoo();
}
@ParameterizedTest
...
0
votes
1
answer
52
views
JUnit 5 ParameterResolutionException: Mixing aggregation with direct binding
I have the following JUnit parameterized test case which uses an aggregator as well as a directly bonded argument. When I run it, I get the following error:
ParameterResolutionException: No ...
1
vote
2
answers
790
views
How to pass multiple arguments to a test method with a @MethodSource annotation and multiple methods that provide Stream<Arguments>?
I have a Junit5 parameterised test method and I need to use my custom DataProvider class with methods that return Stream<Arguments> and are supposed to pass all their arguments to this test ...
1
vote
2
answers
432
views
How can I write a test with Xunit that accepts an enum as parameter?
I try to write a test that looks like this:
private static readonly IEnumerable<MyEnumType> ListOfEnumValues = Enum.GetValues(typeof(MyEnumType)).Cast<DocumentType>();
private static ...
0
votes
1
answer
121
views
Accessing the `UniqueId` passed to a JUnit5 Session from inside an Extension
Background:
https://github.com/sageserpent-open/americium/issues/69
https://github.com/sageserpent-open/americium/issues/66
These concern an extension that generates test data for a JUnit5 test, ...
0
votes
0
answers
443
views
JUnit5 - can I parameterize execution of entire test class?
Starting from the following generic code, showing a sample test class that needs to be executed for several rounds of input data:
import java.util.stream.Stream;
import org.junit.jupiter.api.*;
import ...
0
votes
0
answers
88
views
Access testData from beforeEach for parameterized test
I do want to create test data in the beforeEach method and access that data to give to the parameterized test but I get an error TS2454: Variable testData is used before being assigned.
describe('...
1
vote
1
answer
292
views
Can't parameterize tests by strings
I'm trying to write a parameterized test based on some string values using the Criterion framework. As an MRE, and following the example shown in the docs, I wrote the following:
#include <...
2
votes
0
answers
389
views
JUnit5: Same parameterized test against two different sets (depending on tags)
I have two different sets of parameter sources for a parameterized test (set 1 being a subset of set 2). Depending on JUnit5 tags I want to execute the same test method either against set 1 or set 2.
...
0
votes
0
answers
29
views
Mocha - How to Update parameterized test parameters from before hook [duplicate]
describe('', () => {
let ids = [];
before('',() => {
cypress.api('GET', 'http://localhost:3000/api/id-list').then((response) => {
response.body.foreach((id) => {
...
0
votes
1
answer
148
views
How to pass a function name in parametrize in pytest and How can i use that in testcase?
In the below script i would like to parametrize functions call RegisterClientCabinMovementDetection(x) and RegisterClientOccupantInSeatDetection(x) (made bold in script)so on... is there any way to ...
4
votes
2
answers
6k
views
How to fix the error "Receiver class org.junit.jupiter.engine.descriptor.TestTemplateExtensionContext does not define or inherit an implementation"?
I have the following parameterized JUnit5 test that is supposed to take input data from the method testData
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSHeader;
import com....
0
votes
1
answer
65
views
How do I use pytest fixture dependencies and params at the same time?
I'm trying to create a fixture that has dependencies on other fixtures and is also parameterized. Example:
@pytest.fixture(scope="module")
def fix1():
...
@pytest.fixture(scope="...
1
vote
1
answer
1k
views
Indirect parameterization with multiple parametrize decorators in pytest
First of all sorry in advance if I'm doing this wrong, this is my first question asked on stackoverflow. So please let me know if my formulation is off.
So I'm working on a project where I want to ...
0
votes
1
answer
517
views
changing configuration value in spring-boot app with values of parameterized test
I use this in my MyService.kt.
The useXml is read via application.yml and application-test.yml
@Service
class MyService (
@Value("\${something.use-xml}")
var useXml: Boolean = false
)...
1
vote
1
answer
731
views
Unit test conditional statements using environment variable
I have a source file util.py and there I have below one, where day is an AWS lambda environment variable.
import os
day = os.getenv("DAY")
def get_day_code():
if day == "Monday&...
0
votes
2
answers
74
views
How to reference an object in a class using a decorator
I have a list of dicts defined in setUpClass in a Django TestCase:
class MyTest(TestCase):
@classmethod
def setUpClass(cls):
myobj = MyModel.objects.create()
cls.MY_LIST = [ ...
-1
votes
1
answer
555
views
Reuse JUnit 5 @ArgumentsSource Parameterized test class across different java projects
I have below maven java projects:
com.validator
com.demoModel1
com.demoModel2
Validator project contains the validation code and the jar is used by demoModel1 and demoModel2 projects to perform ...
0
votes
1
answer
1k
views
JUnit 5 Parameterized test @ArgumentsSource parameters not loading
I have created below JUnit5 parameterized test with ArgumentsSource for loading arguments for the test:
public class DemoModelValidationTest {
public ParamsProvider paramsProvider;
public ...
2
votes
1
answer
6k
views
Simple way to have two values as ValueSource for Junit5 ParameterizedTest
I have many boolean methods like boolean isPalindrome(String txt) to test.
At the moment I test each of these methods with two parameterised tests, one for true results and one for false results:
@...
2
votes
1
answer
1k
views
C++ Google Type-Parameterized and Value-Parameterized Tests combined?
I would like to be able to parameterize my tests for various types through the following code snippet:
template <typename T>
class MyTestSuite : public testing::TestWithParam<tuple<T, ...
0
votes
1
answer
454
views
JUnit Testing:How to write parameterized test cases for a program to find the area of a circle using JUnit 4?
The problem is my input to the program is of integer data type and the output is of double data type.So,while writing parameterized JUnit test cases,assertEquals gets striked off automatically......
0
votes
1
answer
556
views
How can I use return of fixture function and data which will be used as parameterized in pytest test case
I get some parameters from command lines.
Then I want to use these parameters as variables in test cases.
I want to use parametrised test in same test case.
Is it correct to run it as below?
conftest....
5
votes
1
answer
3k
views
Is there any way to run setUp and tearDown for each python subTest?
My code:
import unittest
class MyTestCase(unittest.TestCase):
def setUp(self):
print("setUp")
def tearDown(self):
print("tearDown")
def ...
1
vote
1
answer
1k
views
Why have to initialize all variables again in Parameterized JUnitTest although they are intialize in @Before method or at class level
I have one parametrized Junit test in my class. If I initialize all objects used in this test in @Before method they are not accessible in this parametrized Junit test and it throws NUllPointer ...
3
votes
2
answers
2k
views
How to multiply test data sets (cartesian product) in JUnit 5 Parameterized test?
Here is an example of Parameterized test in JUnit 5.
@ParameterizedTest
@MethodSource("generalDataset")
fun shouldCreateItem(color: String, size: String) {
val item = Item(color, size)
...
2
votes
2
answers
4k
views
Kotlin Junit5 ValueSource as an array variable
I have a map of key and values and I want to add the keys as array to ValueSource but I've got error.Where am I wrong?
Here's my code
private val id = mapOf("abc" to 10001,"def" ...
3
votes
1
answer
5k
views
Patch + Parametrize unittest Python
I am trying to parametrize unit tests in Python using parameterize library and unittest framework. I need to patch certain functions and I use the following which works
@parameterized.expand([
[a1,...
2
votes
1
answer
1k
views
JUnit4 - Parameterized test extends parameterized base class - need Cartesian product of them
MyBaseIntegrationTestCase is a class, which is a parent for ~ 150 test classes.
Now, I want to make MyBaseIntegrationTestCase parameterized (parameter is version of external software)
So, I change it ...
0
votes
0
answers
362
views
Parameterized test doesn't work in parallel execution
I try to run my tests with jUnit5 annotation @ParametrizedTest in parallel execution, but it's not work.
public class Simple {
@Inject
private WebSteps WebSteps;
@Inject
private DbSteps dbSteps;
...
3
votes
3
answers
6k
views
Customizing pytest parameterized test name
I've the following tests:
@pytest.mark.parametrize(
"nums",
[[3, 1, 5, 4, 2], [2, 6, 4, 3, 1, 5], [1, 5, 6, 4, 3, 2]]
)
def test_cyclic_sort(nums):
pass
@pytest.mark.parametrize(
...
2
votes
1
answer
525
views
When using JUnit's @Parameterized, can I skip few test data due to bug?
@RunWith(value = Parameterized::class)
class A(private val a: aa,
private val b: bb,
private val c: cc,
private val d: dd
) : UIAutomatorTestCase() {
@Test
fun ...
2
votes
1
answer
2k
views
How to run @RunWith(RobolectricTestRunner::class) and @RunWith(Parameterized::class) together in Junit4
I have to test android application written in Kotlin. I tried
@RunWith(RobolectricTestRunner::class)
public class GeoWindowTest {
@RunWith(Parameterized::class)
class ...
0
votes
0
answers
146
views
Some Junit5 test codes are not run
I am developing an android with Junit5 and Mockito.
Some tests are ParameterizedTest and others are just Test.
Here is my sample code.
When I run this test, only "ParameterizedTests" run.
&...
5
votes
2
answers
8k
views
Passing int array in ParameterizedTest in java [duplicate]
I am trying to pass in an array for testing a certain algorithm, but the arrays seem to not be passed correctly or at all. I manually tested the algorithm so I know it works as it's supposed to. How ...
9
votes
1
answer
3k
views
JUnit5 multiple sources for different arguments (cartesian product)
I am trying to write a test with JUnit 5 which should test multiple combinations of some parameters. Essentially I want to test some cartesian product of inputs from different sources. Consider the ...
1
vote
1
answer
1k
views
Using an array of testinfra_hosts, can you control the parametrized values used for each host in a test?
I'm trying to write a test suite for verifying the state of some servers using testinfra.
It's my first time working with python/testinfra/pytest.
As a brief pseudocodey example
test_files.py
...
0
votes
1
answer
3k
views
parameterized test constructor of junit java error message: Test class should have exactly one public zero-argument constructor
I can really use some help with this parameterized test case I am trying to create. No matter what kind of constructor I create the IDE gives an error message.
Here is my code:
@RunWith(Parameterized....
29
votes
3
answers
25k
views
How to Parameterize beforeEach() in JUnit 5?
I am using JUnit 5 as my Test Runner.
In the setup method, I have hardcoded 3 params (platformName, platformVersion, and deviceName). I have a test method that should test on various combinations... ...
2
votes
1
answer
630
views
Limit infinite stream of arguments in parameterized test
I want to write a ParameterizedTest that facilitates a MethodSource to generate a sequence of random values. Now I'm wondering, if there is any declarative approach to limit the number of tests run.
@...
9
votes
2
answers
8k
views
How to pass a parameterised fixture as a parameter to another fixture
I am trying to avoid repeating too much boilerplate in my tests, and I want to rewrite them in a more structured way. Let's say that I have two different parsers that both can parse a text into a doc. ...
1
vote
0
answers
2k
views
Pytest testing KeyError exception while using parameterize
I am using the @pytest.mark.parametrizefunctionality to test multiple test cases using pytest. Now I am having a hard time understanding how do I test if my function throws a KeyError by default, how ...
0
votes
1
answer
1k
views
How do I include/exclude a JUnit 5 `ParameterizedTest` by name in Maven
I have a parameterized JUnit 5 test, e.g.
@EnumSource(Mode.class)
@ParameterizedTest void shouldRunWithMode(Mode mode) {
...
I want to exclude one of the enum cases from running in Maven, as ...
4
votes
1
answer
1k
views
How to set 2d array as parameter for unit testing
If expected variable is integer, it simply goes like this
[DataRow(2)]
[TestMethod]
public void TestMethod(int expected)
{
// some code...
}
But what should one do when there is 2d array int[,] ...
1
vote
1
answer
2k
views
Parameterized tests with JUnitParamsRunner for Mockito.verify() of different methods
So, I have a method that takes an Object parameter and depending on its value invokes different methods (I use just if statements instead of switch).
public class ClassToTest {
public void ...
84
votes
4
answers
77k
views
Generating display names for @ParameterizedTest in JUnit 5
I have a bunch of @ParameterizedTests that receive parameters from a @MethodSource with quite verbose toString() results (e.g. Selenium's WebDriver). These are used per default to compose the ...
2
votes
0
answers
148
views
Jest test.each with object property in name [duplicate]
I have a parameterized test:
test.each([myObjWithMyPropertyTrue, myObjWithMyPropertyFalse])
('should do something when %o', (myObj) => {
but instead of printing the entire object with %o, I want ...
1
vote
1
answer
1k
views
What is the best practice to write parameterized tests for validating string inputs?
I'm writing a parameterized unit test for a code something similar to below, to make sure that my tests cover all the possible input cases and the system behaves as expected.
I came up with 3 ...
0
votes
1
answer
131
views
Python 2.6 Unittest assistance with parameters and argparse, how to solve?
I am trying to run a basic unit test on Python 2.6 that takes arguments with argparse.
I am limited in my environment and cannot install any further libraries or use any modules for testing but ...