2

I have the following directory and packages using Eclipse and I need to make unit tests on it.

Directory

I've tried a few organizations but they always fail, or don't find the classes to work. When I google how to do it, I always get some vague references to Maven, which I do not know what it is.

Is there a way to move test classes out from main package (in screenshot:UnitTests.java), so it can still be run, but be more organized?

el-teedee
  • 1,293
  • 1
  • 15
  • 27
Rivasa
  • 6,510
  • 3
  • 35
  • 64
  • Maven is a tool for building/packaging your application - it's very commonly used in Java so if you are planning to work in that language it might be useful to learn the basics of it. Anyhow, most of the time, you can create a `test` folder (next to `src`) and have all your test files organized there. – blurfus Sep 04 '18 at 23:33
  • you have to use `maven`, maven provides a standard directory structure for test classes and non test classes. – Jobin Sep 04 '18 at 23:33
  • 3
    @JobinJoseph OP does not ***have to*** use maven - but it will be very helpful as, like you stated, it provides a standard directory structure and approach for these type of things – blurfus Sep 04 '18 at 23:34
  • How do I convert this to maven? Or use it for this project? That or how do I organize it within the test folder? – Rivasa Sep 04 '18 at 23:40
  • To convert to maven, first do a simple reorganization to follow the [maven standard directory structure](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html), and move your tests to the separate test folder. After that, create a `pom.xml` file, for example via Eclipse -- see the question on [converting an existing Eclipse project to maven](https://stackoverflow.com/questions/2449461/convert-existing-eclipse-project-to-maven-project). Then you can use `mvn` from the command line (or Eclipse) to compile, test, and release your code. – avandeursen Sep 12 '18 at 06:37

1 Answers1

1

In short, you can declare another Java package in your project (for example: unittests.com.oop.* and move your test classes in it.

You'll then have com.oop.* containing main classes, and unittests.com.oop.* containing associated unittests.

In long see possible duplicate link

el-teedee
  • 1,293
  • 1
  • 15
  • 27