(1) What should be done if there are different parameter types during parameterized testing in JUint?
时间: 2023-12-31 09:06:33 浏览: 60
If there are different parameter types during parameterized testing in JUnit, then you can use the `@MethodSource` annotation to provide a method that returns a `Stream` of arguments for the test method. In this method, you can define the different parameter types and return them as a `Stream` of arguments.
For example, let's say you have a test method `testAddition()` that takes two parameters - one of type `int` and one of type `double`. You can define a method that returns a `Stream` of arguments for this test method as follows:
```
@ParameterizedTest
@MethodSource("argumentProvider")
void testAddition(int num1, double num2) {
double result = num1 + num2;
assertEquals(10.0, result);
}
static Stream<Arguments> argumentProvider() {
return Stream.of(
Arguments.of(7, 3.0),
Arguments.of(5, 5.0),
Arguments.of(8, 2.0)
);
}
```
In this example, the `argumentProvider()` method returns a `Stream` of `Arguments` where each `Argument` contains two parameters - one of type `int` and one of type `double`. The `@MethodSource` annotation is used to specify this method as the source of arguments for the `testAddition()` method.
阅读全文