I have a project in Java and Spring boot and I am doing my first tests in Java and I wanted to see if I can perform Tests on the code of the project that I currently have, but without copying the content of src/main/java to /src/test/java
From what I understand, I have to make a copy of the code that I have in src/main/java to the tests package and I don't want to copy code every time I have changes in the project's source code. Is there a way to " bind" the content of the source code to perform the unit tests?
Thanks.
It is not necessary to copy anything, you just have to create your unit tests for the operations you need. For example if you have the following:
The only thing you need is some framework to carry out the unit tests, the de facto standard is JUnit, but as you can see, it is not necessary to make a copy in any case.
The structure you're talking about,
src/main/java
andsrc/test/java
they are maven specific, and just put your sources in the first directory and unit tests in the second.Additionally, you must add the JUnit dependency to your file
pom.xml
and that's it, you're ready to do your test withmvn test