Parameterized unit tests is a feature of some unit testing frameworks. It supports executing a given unit test multiple times with different arguments.
Questions tagged [parameterized-unit-test]
116 questions
5
votes
1 answer
Creating parametrized Matlab unittest with complicated properties
I'm trying to create a parametrized Matlab unittest where the TestParameter properties are generated "dynamically" by some code (e.g., with a for loop).
As a simplified example, suppose my code is
classdef partest < matlab.unittest.TestCase
…

Frank Meulenaar
- 1,207
- 3
- 13
- 23
5
votes
1 answer
Adding more information when JUnit 4 timeouts with parameterized runner
I am running a JUnit 4 test using @RunWith(value = Parameterized.class). This works fine, no problems there. However, when any of my 34 tests timeout, I only get the message java.lang.Exception: test timed out after 15000 milliseconds. I want it to…

Simon Forsberg
- 13,086
- 10
- 64
- 108
5
votes
3 answers
.NET test framework with parameterized unit testing, that shows red/green for each combination?
Parameterized Unit Testing is great when you have X unit test * Y configurations.
I have 3 unit tests, and each must run in 5 particular situations.
I use xUnit.net's Theory/PropertyData feature, it works well.
PROBLEM: In the Test Runner UI, there…

Nicolas Raoul
- 58,567
- 58
- 222
- 373
4
votes
2 answers
Passing int array in ParameterizedTest in java
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 can I pass arrays in for testing in JUnit…

Noah Iarrobino
- 1,435
- 1
- 10
- 31
4
votes
2 answers
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. That doc would then be used in other tests. The…

Bram Vanroy
- 27,032
- 24
- 137
- 239
4
votes
2 answers
Is there a way to create a custom parameters generator with googletest?
I am actually using googletest framework. I have a value parameterized test with
std::tuple
This int represents the number of vertices in a regular polygon and the double represents its radius. I could represent this using a struct…

Jo Ham
- 149
- 1
- 11
4
votes
1 answer
Use Values- and Range-Attribute in NUnit TestFixture constructor
I have multiple test methods which should test all possible combinations of multiple parameters. I can use the NUnit ValueAttribute or RangeAttribute on methods like this:
[TestFixture]
public class MyExampleTests
{
[Test]
public void…

Xarbrough
- 1,393
- 13
- 23
4
votes
2 answers
How do you write a parameterized test using specs?
I have several different implementations of a trait that I would like to test, and the test only uses the method signatures of the trait, so it seems like I should be able to use parameterized tests. However, the specs2 website doesn't seem to…

nnythm
- 3,280
- 4
- 26
- 36
3
votes
1 answer
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 test_something(self):
for i in range(4):
with…

Searene
- 25,920
- 39
- 129
- 186
3
votes
2 answers
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)
…

diziaq
- 6,881
- 16
- 54
- 96
3
votes
1 answer
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[,] instead of int parameter?
When I try to do…

Andrey
- 65
- 8
3
votes
1 answer
Using custom types for parameterized MSTests
I'm creating unit tests, and I'm wanting to create parameterized tests using custom types (like a dto).
I'm wanting to do something like this:
[TestMethod]
[DataRow(new StudentDto { FirstName = "Leo", Age = 22 })]
[DataRow(new StudentDto {…

Leo Reyes
- 101
- 3
3
votes
1 answer
How to generate method parameters based on class parameters for Matlab unit tests
A program I am working on performs calculations that involve objects that can only have several possible sets of values. These parameter sets are read from a catalogue file.
As an example say the objects are representing cars and the catalogue…

Tim
- 1,430
- 15
- 36
3
votes
3 answers
Test different methods with different subset of data in JUnit test case
Say I have a JUnit test case as:
@RunWith(Parameterized.class)
public class TestMyClass {
@Parameter
private int expected;
@Parameter
private int actual;
@Parameters
public static Collection

Anmol Gupta
- 2,797
- 9
- 27
- 43
3
votes
1 answer
Junit Test Case constructor calls in parameterized runner
I wrote a long parameterized test, one of whose parameters is a constructor call with double-brace syntax to construct a different object for each row of the 2D array:
Object[][] data = new Object[][] {
{ 1, 2, 3, new Blah() {{ setA(); }} }
{ 1, 2,…

orbfish
- 7,381
- 14
- 58
- 75