Is it possible to run incremental/automated JUnit testing in Eclipse? - java

Eclipse support incremental compiling. If I save a source file then it will compile the modified files.
Is it possible after such incremental compile also to run the JUnit tests of the same package and show the fail in the error view. Then I can see the JUnit test failing and compiling errors in the same view without extra action. Are there any plugins that can do it?

You have to look at these plugins:
JUnit Max: Not free, developed by Kent Benk (one of the men behind the TDD practice);
MoreUnit: Free, but essentially dedicated to help you write the tests;
Infinitest: Now free, this plugin is dedicated to run the tests related to the files you have just modified.
So regarding your needs, I suggest that you install MoreUnit and Infinitest plugins.

Use ExternalToolBuilder.
It can be triggered by source modify.
There’s Eclipse customized feature(integrate external tool builder) which may meet your need. But it needs extra effort to write the scripts I never used. Automatic test cases is not a convenient way, at least single click to see green bar in Eclipse is enough for me:)

You can run all tests in a project using Alt+Shift+X,T. I think that making it any more automated than this could take a serious performance toll. Incremental compilation is compiling at most 1 file at a time, but you're talking about running potentially hundreds of tests.

Related

How to organize different java source folders in netbeans (for testing)?

I am developing a project in Netbeans (8.0.2) that uses JUnit (4.x) for testing application code (in a Netbeans module). In the same module I also have some integration tests. I found a way to separate application code, unit tests and integration tests by putting the latter into a separate folder under MODULE_PATH\test\qa-functional\src. By that, the Netbeans IDE puts those three semantical different kinds of classes into individual folders:
The problem is, my functional tests tend to grow complex, so I would prefer to have them, well, unit tested. However if create a unit test (in the Unit Test Package) for a class of the functional test package, the test does not compile. Seems to be some class path issues.
I know I can put the unit test of the functional test in the functional test package as well (and I will do so if this question does not provide me with some solution), but anyway, is there a way to solve this in Netbeans?
I found a bad solution, changing the order of ant targets in common.xml (in line 610 of NB 8.0.2). But that is obiously not portable, changes with a new version of Netbeans,.. So not really a solution. See details in Netbeans Forum: Classpath problem when unit testing functional tests
In Eclipse, I would simply add a new source folder on the Java build path. But that mechanism does not exist in Netbeans?
For clearification, I added a screenshot.
Thanks in advance for your help.
You are are trying to do a wrong thing:
unit tests should verify the smallest possible functionality, e.g. that a method is producing the expected result
functional tests in NetBeans represent integration tests, tests when you treat the application as a black box
It does not make sense to "unit test" the functionality in the "functional tests". NetBeans treats the tests folders independent so that they are not on each other's classpath, that's why it does not work in NetBeans.

Continuous testing with IntelliJ Idea

I'm looking for an IntelliJ IDEA plugin that would run my tests each time I change my code. I looked for such a solution and I found:
Infinitest, which works, but is inconvenient because I need to add the facet to each module, and it opens a new tool window for each module (which means 15 tool windows for me).
Fireworks - didn't work for me, maybe it just doesn't work with IDEA 14 (in its repo I can see that last changes were made in 2009). IntelliJ also reports that it throws exceptions.
There are lots of ways I could run all my tests (including writing a simple script for this), but I'm looking for a tool that would be smart enough to rerun failed tests first, and that would understand module dependencies (so after a change in some module it would run only tests of dependent modules).
I prefer free options, but if there's something paid for a reasonable price, I would accept it as well.
IntelliJ now actually has a Toggle auto-testin the run dialog. Just run a run-configuration and then select Toggle auto-testin the run dialog.
It's not as intelligent as you would have hoped. It just reruns when it detects changes.
I know this is a 3-year-old question but I think it will help people who face the similar problem in future. So I found out a way to enable SBT style auto test execution in IntelliJ studio.
We need to do 2 things to enable auto test execution.
Enabling auto project build - This can be done in settings by going into File -> Settings -> Build, Execution... -> Compiler and selecting "Build Project automatically".
Enabling "Toggle auto-test" in run dialog box
This will start auto testing. Although this works fine, it takes time to build the project even when my project is tiny so for larger projects it will certainly take very long time to complete the build and execute tests.
Reference: Original article which explains these steps
If you are OK running tests which cover a single method chosen by you, you can try this plugin (it is continuos in the sense that you make changes to a method, then click on the method and the plugin will run all the unit tests automatically which cover that method): https://plugins.jetbrains.com/plugin/15063-unit-test-coverage-history-runner
You can use the Intellij Teamcity plugin. Teamcity is a paid product but there is a free version which gives you 20 projects and 3 agents for free .
It has a remote run feature using which you can send in unchecked code to run tests before committing.
It also has options to run failed tests first
Usage instructions for Remote Run

Creating a program that will run before and after compilation in Eclipse

I am currently working on a small program that should comment out some code used for testing.
I want it to auto run before the compiler while compiling the release version and another program that will comment the code back in after compilation was over.
The program works the only thing I am missing is to add it to the build process.
Thanks to all helpers!
In Eclipse, right-click a project, choose Properties → Builders and click New. You can add an Ant script or a command line that Eclipse will trigger when building the project. You can also control the order of builders in the same dialog.
However, I agree with JB Nizet – there are many advantages to having Ant or Maven build your project.
Don't use Eclipse to build the release version of your app. Use Ant, Maven, or any other build tool that is much more flexible than Eclipse, doesn't need a GUI, can be scripted and used by a continuous integration server.
All of these tools should easily be used to include your pre-compilation and post-compilation tasks in the build process.
That said, you could just use a public static final boolean constant FOR_TEST, and include all your testing code in
if (TestUtil.FOR_TEST) {
}
You would then have just a single place to change in the code to have all the test code removed from the compiled version. No need for a complex Java program to do that.
Or you could let all the testing code in the released version, and activate it when testing using a system property, for example. This wouldn't even need any precompilation/postcompilation phase, and would probably have a negligible cost.

Automatically create testcode from class (jars

We have thousands of classes without any true unit test coverage. As special project we aim to add reasonable coverage to all. One option is to create tests from sourced code and use GenerateTestCases plugin with IJ.
I am exploring other options to create tests massively..
Is it possible to create tests (okay, just test-templates) from class files? TestGen4J does this, but the project seems to be inactive. Is there any tool that could help in creating the tests for thousands of classes.
Once such tests are generated, I hope we have more momentum to add more unit tests for existing classes.
Google CodePro Analytix eclipse plugin can generate the unit tests automatically for you and it is actively maintained.
you can try netbeans tools too, select the class and right click tools/create Junit Test but its manual and ugly task to thousands files

How to avoid wasting time during compilation during development?

I'm working with a small team of developers. My job is to convert a Make project (with Intellij Idea 9.0) into a Maven 2 project.
The problem is : we spend a lot of time during the development. With Make, only one complete build was required and then any change did not consume a lot of time (almost instantaneously). On the other hand, with Maven 2, a little change takes a lot of time to run.
Any solution ? Thanks.
The problem you're facing and its description are not clear (what is your project structure, how you build it, how much time does it take to compile one change, etc) but here are some practices that could help:
Use incremental builds (i.e. don't use clean at each build).
Use binary dependencies (i.e. multiple modules with dependencies vs of a huge monolithic module).
Use advanced reactor options for smart reactor build (to build only the required subset of modules).
Use Maven Shell (if you're not aware of this project, CHECK IT OUT).
Personally, I'm not experiencing "lot of time to run" problems with my projects.
On the other hand, with Maven 2, a little change takes a lot of time to run.
I'm not really sure that this has to be true. For a single Maven project, the compile phase doesn't need to recompile all source from scratch, just what has been updated since the last run (assuming you haven't done a clean, etc.).
Without further details though it's hard to offer any advice. Have you converted to Maven and are finding that it seems to be excessively re-building many parts of your projects? If so, please provide more details as Pascal mentions aboves. Or is this just a question driven by fear?
IntelliJ can load the module/project configuration from the pom files. This means that during development, use IntelliJ's build based of the pom files (which is incremental and quick) and only use maven stand alone for continous integration and releases.

Categories

Resources