2

I started learning JUnit testing within Eclipse. The plugin that is used to show the test results presents a nice clean view of the test and you can click on items that take you to the areas in code that are under test.

When I started working with Maven, I noticed that you can have Maven carry out your JUnit tests as well. However, because Maven is a command line process and the results get written to the console, the JUnit results get sent there as well. And it looks like crap. You have to parse your way through all the console text to find the results of the test. Everything is just plain old text.

This raises the question as to what purpose Maven has in testing with JUnit (or any other test frameworks for that matter)? I must be missing the point. Why would anyone want to read a large text dump when the Eclipse plugin provides an elegant way of viewing, executing and evaluating tests?

Johann
  • 27,536
  • 39
  • 165
  • 279

3 Answers3

3

Generally speaking, you build on the command line because you've got everything working correctly in your IDE. The command line build is the final sanity check and possibly the way in which you are releasing your software (e.g. mvn release:perform etc.).

While there are a few plugins that make Maven test output slightly nicer, the expectation is that the tests will pass. If they don't, fire up Eclipse and run the tests again.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • Which means I am suppose to parse through all the console text to determine whether the tests past? – Johann Apr 14 '14 at 08:07
  • @AndroidDev Maven tells you if your build failed because of tests. At that point, I probably wouldn't even bother looking through the output to see which tests failed. I'd switch to Eclipse and run the tests again there to see what happened. – Duncan Jones Apr 14 '14 at 08:09
  • So then you really did answer my question. Maven has no value for testing other than a single pass/fail indication. The real testing is all done within Eclipse. – Johann Apr 14 '14 at 08:30
  • @AndroidDev That is probably a valid view point if you are a single developer working on a project. In larger projects, the output from Maven is often fed into project reports etc. which can be rather helpful. – Duncan Jones Apr 14 '14 at 08:32
3

Maven is a build tool. Its goal and purpose is to produce repeatable and protable result. This is especially important when we talk about build/continuous integration servers.

So the normal workflow is/should be: Developers usually develop using their IDE (eclipse), they run their tests in the IDE, because it is developer centric and more comfortable.

The build server, lacking a graphical environment runs the build tool, i.e. maven.

Sometimes, the results between maven and the eclipse might differ, in that case might become necessary for developers to also run maven on their machine.

Another reason to use maven directly might be integration test which specifically us maven lifecycle integrations for say starting and stopping a server.

Some specific points: Maven quite comfortably shows you which tests failed in a summary:

00:46:21.988 Results :
00:46:21.988 
00:46:21.988 Failed tests: 
00:46:21.988   MyTest.testPersistErrorStateNewTransaction:48 Test for 'testPersistErrorStateNewTransaction()' not yet implemented!
00:46:21.988 
00:46:21.988 Tests in error: 
00:46:21.988   MyOtherTest.testMethod
00:46:21.989 
00:46:21.989 Tests run: 1162, Failures: 1, Errors: 1, Skipped: 491
00:46:21.989 
00:46:22.003 [ERROR] There are test failures.
00:46:22.004 

Also, when run, from maven, you can still open the results of the surefire tests in your eclipse junit view by double-clicking on a test result (.xml) in the surefire-reports directory.

blackbuild
  • 5,026
  • 1
  • 23
  • 35
  • 1
    I did not know that you can open the .xml file in the JUnit Eclipse plugin. Thanks for that! – Behe Apr 14 '14 at 10:01
2

what purpose Maven has in testing with JUnit?
Unit testing is one of the part in Application Development(usually do while coding/developing components), Apache Maven is the project management tool, (as Duncan told) it helps us to releasing software. includes - Dependency Management, Module Management, Plugin Management, and reporting configuration for tests.

Maven Objectives:

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features

please look at below threads for more details about Maven:
Why do so few people use Maven?
Why maven ? What are the benefits?

Why would anyone want to read a large text dump when the Eclipse plugin provides an elegant way of viewing, executing and evaluating tests?
For software release purpose we need maintain statistics of the application(how many scenarios covered, test cases passed..etc). Maven supports different plugins to format the results, Maven Surefire Plugin, maven-site-plugin..etc plugins help us to generate reports different formats.

please refer below threads for more details:
JUnit3 and Junit4 XML Reports with Maven
Is there a decent HTML Junit report plugin for Maven?

Community
  • 1
  • 1
Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
  • I think this answer might benefit from some editing - there is a lot of extra information about Maven that doesn't seem relevant to the question. Only your final two paragraphs seem relevant. – Duncan Jones Apr 14 '14 at 08:14