A
A
Alexander K2021-01-13 19:26:08
Java
Alexander K, 2021-01-13 19:26:08

What needs to be done to make the JUnit test run as TestNG?

Here is the JUnit test
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.provider.CsvSource;

public class StudentTest {
/* parameterized test for the avgAge() method for calculating the average age using the @CsvSource annotation */
@ParameterizedTest
@CsvSource({
"24,"
+ "Alexandr, Ivanov, 20,"
+ "Vladimir, Petrov, 18, "
+ "Aleksey, Alekseev, 35"
})
void avgAge(int expected, ArgumentsAccessor arguments) {
Student[] students = {
new Student(arguments.getString(1), arguments.getString(2), Integer.parseInt(arguments.getString(3))),
new Student(arguments.getString(4), arguments.getString(5), Integer.parseInt (arguments.getString(6))),
new Student(arguments.getString(7), arguments.getString(8), Integer.parseInt(arguments.getString(9))),
};

assertEquals(expected, Student.avgAge(students));
}
}

I guess it looks like this in TestNG
import org.testng.annotations.Test;

public class TestNG {

@Test
public void avgAgeTest() {
throw new RuntimeException("Test not implemented");
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question