O
O
office12018-10-22 23:02:39
Java
office1, 2018-10-22 23:02:39

What is the correct way to use common methods for unit tests?

There are several classes with Unit tests. In each class, tests should use the method of reading from files

private String readFromFile(String fileName){
...
  return result;
}

Where and how to correctly move this method so that it is common for test classes? What is the correct approach to solve such problems?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evhen, 2018-10-23
@EugeneP2

The readFromFile method is done with default access:

String readFromFile(String fileName){
...
  return result;
}

And the JUnit test itself is placed in the same package as the class under test, so that it has access to the readFromFile
method src/main/java/ com/demo/file /FileReader.java
src/test/java/ com/demo/file / TestFileReader.java

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question