4

I have to make some Java classes within a package using Netbeans. I have a question about the order I am supposed to do the following tasks: We are supposed to create unit tests, Javadoc things, and build the project (to make a JAR file that contains our class library). We will need to clean and build the project when we make changes. Can I start unit testing and documenting my code now before I have explicitly built the project? Or do I need to run the build first to pull things all together and then start unit testing and document with JavaDoc? Thank you for any help! Googling and searching here was getting me no where.

neoteric
  • 49
  • 1
  • 2
  • 2
    I don't really understand the question. What prevents you from doing whatever you want? All that should matter is that in the end, you can build the project, you can generate javadoc, and you can run (and pass) the tests. Whether you run a first build before writing your first test doesn't really matter. You'll launch the build and run the tests many many many times before ending the project. – JB Nizet Feb 07 '17 at 20:44
  • Oddly enough that basically answers my question! I didn't know if there *was* something stopping me from doing it in any order. :) – neoteric Feb 07 '17 at 21:26
  • This is a very good question. I recently had an argument with a co-worker: he said that a build was needed for the unit tests to run; I argued that unit tests are completely independent of the build. I'm assuming (from JB's response) that I'm correct. :) – SMBiggs Oct 05 '22 at 21:42

2 Answers2

0

You'll need to have compiled the code before you can run tests on it.

Generally, a build system is responsible for managing all the steps, from assembling dependencies, through compiling, testing, and packaging. Different tools are optimized for different parts of the flow, though.

If you're starting up a Java project, I would recommend Apache Maven as a good all-in-one build system. Many other options and configurations exist, though.

Daniel Pryden
  • 59,486
  • 16
  • 97
  • 135
0

There is no one answer for this question.
The more traditional way is code first and than tests, however, there is a design approach called TDD - test driven development. in this approach you actually start from the tests, and add the code according to failed tests.

You can read more about it here

Essentially, there's no right or wrong here, it depends on what you find more convenient

Nir Levy
  • 12,750
  • 3
  • 21
  • 38