A
A
Alexander K2021-01-06 14:18:26
Java
Alexander K, 2021-01-06 14:18:26

Why did I get the error - Method dynamicTest(String, () -> {}) is not defined for type StudentTest?

import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;






public class StudentTest {
  /*объект тестового класса  Student*/
     	   
  
      
  @TestFactory
  Stream<DynamicTest> dynamicTestsGetters() {
      
      Student[] studentsObjects = {new Student("Alexandr", "Ivanov", 20), new Student("Vladimir", "Petrov", 18), new Student("Aleksey", "Alekseev", 35)};

      String[] firstNameTest= {"Alexandr", "Vladimir", "Aleksey"};
      String[] lastNameTest= {"Ivanov", "Petrov", "Alekseev"};
      Integer[] ageTest = {20, 18, 35};

      List<DynamicTest> dynamicTests = new ArrayList<>();

      for(int i=0; i < studentsObjects.length; i++) {
          int j = i;
          DynamicTest dynamicTestFirstName = dynamicTest("DynamicTest getFirstName("+firstNameTest[j]+")", () ->{assertEquals(firstNameTest[j],studentsObjects[j].getFirstName());});
          DynamicTest dynamicTestLastName = dynamicTest("DynamicTest getLastName("+lastNameTest[j]+")", () ->{assertEquals(lastNameTest[j],studentsObjects[j].getLastName());});
          DynamicTest dynamicTestAge = dynamicTest("DynamicTest getAge("+ageTest[j]+")", () ->{assertEquals(ageTest[j],studentsObjects[j].getAge());});

          dynamicTests.add(dynamicTestFirstName);
          dynamicTests.add(dynamicTestLastName);
          dynamicTests.add(dynamicTestAge);

      }
      	
      return dynamicTests.stream();
  }

}
5ff59c7cf170b560145689.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2021-01-06
@a6l6e6x

Because the dynamicTest method is not declared anywhere in the StudentTest class.
Perhaps you mean:

DynamicTest dynamicTestFirstName = new DynamicTest(...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question