Questions tagged [parameterized-unit-test]

Parameterized unit tests is a feature of some unit testing frameworks. It supports executing a given unit test multiple times with different arguments.

116 questions
365
votes
25 answers

How do you generate dynamic (parameterized) unit tests in Python?

I have some kind of test data and want to create a unit test for each item. My first idea was to do it like this: import unittest l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]] class TestSequence(unittest.TestCase): def…
Peter Hoffmann
  • 56,376
  • 15
  • 76
  • 59
307
votes
39 answers

No tests found for given includes Error, when running Parameterized Unit test in Android Studio

I have tried to run Parameterized Unit Tests in Android Studio, as shown below: import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; import org.junit.Test; import org.junit.runner.RunWith; import…
Elye
  • 53,639
  • 54
  • 212
  • 474
96
votes
7 answers

JUnit test with dynamic number of tests

In our project I have several JUnit tests that e.g. take every file from a directory and run a test on it. If I implement a testEveryFileInDirectory method in the TestCase this shows up as only one test that may fail or succeed. But I am interested…
Dr. Hans-Peter Störr
  • 25,298
  • 30
  • 102
  • 139
75
votes
6 answers

MSTest Equivalent for NUnit's Parameterized Tests?

NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times. [RowTest] [Row(1001,1,2,3)] [Row(1,1001,2,3)] [Row(1,2,1001,3)] public void SumTests(int x, int y, int z, int expected) { ... } What's…
blaster
  • 8,876
  • 11
  • 48
  • 77
68
votes
8 answers

Create multiple parameter sets in one parameterized class (junit)

Currently I have to create a parameterized test class for every method that I want to test with several different inputs. Is there a way to add this together in one file? Right now there's CalculatorTestAdd.java which has a set of parameters that…
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
50
votes
4 answers

JUnit5 parameterized tests at class level

Is it possible to use JUnit5's parameterized new features to run test classes to receive test parameters instead of doing it at method level? With JUnit 4 a runner such as @RunWith(Parameterized::class) plus inheritance could be used to pass an…
IS1_SO
  • 865
  • 3
  • 10
  • 16
48
votes
5 answers

jasmine parameterized unit test

Okay as a C# NUnit guy this might be odd. But does jasmine allow parameterized unit test? I am not sure if it goes against the "declare" and "it" to make things readable to non programmers. I have seen some third party plug ins but they are kind of…
44
votes
1 answer

Google Test: Is there a way to combine a test which is both type parameterized and value parameterized?

I know how to develop a type-parameterized test and value-parameterized test separately. What I am trying to figure out is if it's possible to combine both. In other words, create a generic test which takes any type and range of values for that…
linux fanatic
  • 551
  • 1
  • 6
  • 8
44
votes
4 answers

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 corresponding display names. From the JUnit 5 user…
beatngu13
  • 7,201
  • 6
  • 37
  • 66
29
votes
6 answers

Writing a re-usable (parametrized) unittest.TestCase method

Possible Duplicate: How to generate dynamic (parametrized) unit tests in python? I'm writing tests using the unittest package, and I want to avoid repeated code. I am going to carry out a number of tests which all require a very similar method,…
astrofrog
  • 32,883
  • 32
  • 90
  • 131
25
votes
5 answers

Can I write 'parameterized' tests in DUnit

I am using DUnit to test a Delphi library. I sometimes run into cases, where i write several very similar tests to check multiple inputs to a function. Is there a way to write (something resembling) a parameterized test in DUnit? For instance…
Mathias Falkenberg
  • 1,110
  • 1
  • 11
  • 25
21
votes
3 answers

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... This means, when running my testLogin() test, it…
cpro
  • 225
  • 1
  • 2
  • 6
20
votes
6 answers

Parameterizing with array in Junit 5 (or other testing Java library) in smarter fashion

I'm trying to parameterize this test: @Test public void reverseQuote(double[] qsp) throws Exception { ...} It seems absurd to me that it doesn't exists some quick method to initialize array qsp like, for example,…
Lore
  • 1,286
  • 1
  • 22
  • 57
20
votes
7 answers

Parametrized unit tests in Swift

Is there any way to use parameterized unit tests, similar to what you can achieve in .Net using NUnit framework. [TestCase(12, 3, 4)] [TestCase(12, 2, 6)] [TestCase(12, 4, 3)] public void DivideTest(int expectedResult, int a, int b) { …
Maciej Jastrzebski
  • 3,674
  • 3
  • 22
  • 28
17
votes
3 answers

How to pass a list as a JUnit5's parameterized test parameter?

I want to parameterize my JUnit5 tests using three parameters: string, string and list. No luck so far when using @CsvSource, which is the most convenient way of passing params for my use case: No implicit conversion to convert object of…
Grzegorz Piwowarek
  • 13,172
  • 8
  • 62
  • 93
1
2 3 4 5 6 7 8