eclipse + m2e + junit + infinitest + eclemma? - eclipse

I have Eclipse for Java Developer 4.3 with m2e, eclemma, infinitest. My project uses Eclipse m2e with junit 4.11.
My intention is to have coverage info updated every time infinitest re-runs the tests affected by last save. Is it possible?
At the moment I'm able to manually run a test with Coverage and see code highlighted, but when I change code infinitest kicks in and coverage highlight disappears.

I created a run configuration for JUnit, which aggregates all tests in a specific scope - java/test/src in my case - and executes them.
I call it from time to time to update the coverage information. Depending on how many test cases or suits you have, what you intend may slow down your working process.
Alternatively you could add some kind of hook to every test case you write. If infinitest detects changes and executes a test, every other gets called too. But I wouldn't recommend that.

Related

How can I convince eclipse/JUnit4 to find all my tests, in a gradle/eclipse project?

Background
JUnit 4 test runner, within Eclipse 4.11.
I have an eclipse project that was imported from a build.gradle file. This project has several different source paths, each with their own test path.
main/java, test/java, foo/java, fooTest/java, fooTest/resource, and so on.
Problem
When I run a "whole project" JUnit configuration (debug, run, code coverage, whatever), all it finds are the tests within "test/java". I have successfully added new test classes and new #Test methods within this folder.
Tests from any other source path are ignored when I try to "Run all tests in the selected project, package, or source folder". Furthermore, selecting the specific source folder 'fooTest/java' errors out with the message "No tests found with test runner 'Junit 4'". However, when I use the "Run a single test" option with a specific test class, it finds all its test methods just fine. I can specify a particular method and the test runs just fine.
Stuff that didn't work
I tried changing the output directories of my non-main test source paths to write to the same folder as my working test source path. No joy.
I tried various settings of Eclipse's "Contains test sources" flag for my different test source paths. On or off, the behavior is the same across all my test source paths. /test/java is always found, fooTest/java is always missed. No, I haven't tried all 16 permutations of the flag across my 4 different test source paths.
I tried ripping out all the gradle-related stuff from the .project and .classpath. No change in behavior. Dammit... got my hopes up.
I tried changing the order of the <classpathentry/> in the .classpath project file. When I moved test/java such that it was no longer the first test path, I once again got the "no tests found" error, just like when I aimed the junit configuration "run all tests in the selected project, package, or source folder" at one of my other test source folders. Putting it back restored the original behavior.
Does anyone have further suggestions I could try to make my remaining tests run without individual configurations for every test class that I must manually run one at a time?
I switched to the JUnit 5 test runner, and it picked up on everything just fine. It's vintage package was able to find all my JUnit 4 tests, and I've since modified several tests to use the newfangled annotations and Assertions in JUnit 5.
Perhaps this was a known bug/limitation in the JUnit 4 runner? Ah well. It works now.

Scala Intellij breakpoints ignored

I am doing the Scala introductory course from Coursera.
Within Intellij, I am trying to debug but breakpoints are ignored.
Unlike in this question: Can't debug a Scala application in IntelliJ + sbt-idea-plugin, I am not getting any error.
Do I need to install something or set some Intellij configurations?
Someone recently walked me through debugging in InteliJ using scala/scalatest. I am running InteliJ Idea 2017.2 with the latest scala language plugin installed, no SBT plugin installed (as far as I can tell this is just part of the scala plugin now). Hopefully this helps some other people out:
Set breakpoints by clicking next to the line number you want to test.
Assuming you are using ScalaTest to set up some conditions and run your program, you can right-click on one of your test classes, and then select Debug '[classname]' from the dropdown. This should pop open the debug pane on the bottom.
When you use InteliJ to run the debugging directly (not attaching through sbt etc) I was actually able to get this to work. I have not had success with any of the answers to related questions that discuss attaching to a running sbt process (with scalatest at least).
There are a lot of useful things that intelij debug gives you with scalatest at this point. Say there is one test that is failing and you want to dig into why. On the debug window, click the console tab, and you will see a list of your tests ordered by suite w/ red marks next to the ones that failed. You can right-click on a single test and select debug from the dropdown to only debug that one test. It's pretty useful.
Hopefully that helps some other people! I also hit a few gotchas I should outline:
Sometimes I need to re-load the sbt project (click the circular arrow thing under the sbt project tab on the left). It takes a while but it cleans up some random errors about classes not being found, and even unrelated sounding things like One or more requested classes are not Suites.
I sometimes get errors about shaded classes not found, especially when using docker through sbt (for example to spin up a db node in my tests). To get around that I first deleted the cached compiled jar (rm -r $HOME/.ivy2/cache/com.spotify/ for example to get rid of the cached compiled code that was causing problems) then I reloaded the project as in step-1.
If all else fails, make sure that the project is properly imported. You might need to delete the .idea folder in your folder and re-import the sbt project. This trashes your settings and all, but it's worked for me as a last resort in the past.

Using Maven for JUnit testing

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?
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.
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.
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?

Is there a problem-free way to run Scala 2.7.7 unit tests in Eclipse integrated nicely?

I'm developing Scala code using Eclipse, often when I run tests I get this error:
No tests found with test runner 'JUnit 3'.
Environment:
Eclipse for Java Developers, 3.5.1
Scala 2.7.7
JUnit 4.7
I'm currently writing my tests as JUnit3 tests, and invoking them by right clicking on a package in the project explorer, choosing Run As -> JUnit Test. (I was writing them as JUnit4 tests but ran into even more problems.)
If I fire up eclipse, the tests may not run unless I first open the source code file for the test. If I do open the source code file for the test, it will run. However, often then when I make any modification to the test file or any other source code file, Eclipse will refuse to run my tests, saying: "No tests found with test runner 'JUnit 3'."
I just repeated this just now:
Open eclipse
Open the .scala file with some tests
Invoke the tests by right clicking on the package for that file in the project explorer and choosing Run As -> JUnit Test
It ran the tests
One failed
I changed a string literal in the failing test to fix it
I then re-launced the test using the same method, and I get the dreaded "No tests found with test runner 'JUnit 3'."
I get this same method using other methods of launching the tests, e.g. JUnit buttons or menus to re-run all or some tests
To get the tests to run again I close and re-open Eclipse... So I end up relaunching Eclipse many many times a day.
Note: I do often use XML literals in my tests, I wonder if that has anything to do with it.
2nd Note: See my answer to this thread: What is the current state of the Scala Eclipse plugin? where I described some of the other problems I'm having with Scala+Eclipse. Most of the problems are just minor annoyances, but this test invocation problem is a real time waster, would love to find a way around it!
This Just works on trunk ... JUnit 3 and 4 unit test are detected and Run As => JUnit test does the right thing.
Oh, and BTW, the best way to get my attention on this sort of thing is to file a bug or enhancement ticket in Trac rather than posting messages to StackOverflow (even though it worked this time ;-)

How do I configure Eclipse to run your tests automatically?

I read this article: Configure your IDE to run your tests automatically
http://eclipse.dzone.com/videos/configure-your-ide-run-your
It's pretty easy to configure Eclipse IDE to run an Ant target every time a file is saved.
MyProject -> Right-click : Properties -> Builders -> New -> Ant Builder
The problem is that the builder has to rebuild the jar on every save, which is very long. The JUnit tests run using the .classes in the jar.
We already have JUnit configurations (EclipseIde .launch files which contains the whole classpath to run the tests). I wish I could create a builder that wraps those JUnit launch files. This would have the benefit of running the tests against Eclipse .classes (faster than rebuilding the jar). Also the test results are displayed in the JUnit view.
Has anybody manage to do that?
I recently started using Infinitest and it seems to somehow "know" which parts of the code affect which test cases. So when you change some code, it automatically re-runs the tests which are likely to break. If the test fails, it marks an error at the spot where it failed, the same way Eclipse would mark a coding error like calling a non-existent method or whatever. And it all happens in the background without you having to do anything.
You could try CT-Eclipse, a continuous testing plugin for Eclipse.
From the plugin page:
With CT-Eclipse enabled, as you edit your code, Eclipse runs your tests quietly in the background, and notifies you if any of them fail or cause errors.
You can use JUnit Max it is an eclipse plug in that will run all you tests every time you save. But it will do it without interrupting your work flow. The results are shown in the left corner of Eclipse and you can always go back to the last successful testrun. The plugin runs the tests that are most likely to fail first so that you get a response for your last saving as fast as possible.
http://www.junitloop.org/index.php/JUnitLoop is another one like this (haven't tried it yet myself)