Update multiple eclipse run configuration user classpath setting - eclipse

Background:
ProjectA is an Eclipse 4.2.1 java project with numerous junit 4 test classes. Each junit test is run individually at times and therefore has a corresponding run configuration. Each run configuration specifies a configuration folder from ProjectB as a user class path entry.
ProjectA
test
classATest.java (run configuration user class path entry -> ProjectB/config)
classBtest.java (run configuration user class path entry -> ProjectB/config)
...
ProjectB
config *deleted*
ProjectC
config *created*
Question:
If the configuration folder is moved from ProjectB to ProjectC, is there a way to perform a mass update of all the junit run configurations with a new user class path entry.
Constraints:
Maintaining a copy of the configuration folder and contents in ProjectA is not desirable because it is frequently updated. Updating each run configuration by hand is not desirable. Adding the junit test classes to a junit suite and having a single run configuration would possibly work, but in order to run an individual test I would need to run the suite, kill it, and run the individual test from the junit window.
Attempted:
I was unable to find a way to perform this type of update through the eclipse GUI. Maybe manipulating the eclipse files directly would work.
Thanks in advance.

According to this, eclipse stores run configurations in :
<workspace>/.metadata/.plugins/.org.eclipse.debug.core/.launches
So, using a find/replace function in a text editor or linux test manipulation programs it should be trivial to refactor the run configurations with new user class path entries.

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.

Working on an Eclipse project (using Builders) in IntelliJ

I've recently been tasked with working on an existing eclipse project that makes use of Builders to run Ant tasks under given conditions. I've never heard of Builders before yesterday, and I'm having difficulties getting the project to work in IntelliJ.
First of all, I would like to know if there is a way I can effectively trick Ant into running from a different base directory than what it already does. Consider the following screenshot from Eclipse:
Here, project A is running an Ant task in a local build file that extends a build file from project B. As you can see from the Base Directory setting, it is different from that of A. When I try to run the task from this build file in IntelliJ, I get build errors because certain directories do not exist in the folder for project A -- they are located in project B.
Secondly, this Builder is set to trigger on Manual Build and Auto Build, but my understanding is that this only triggers if the project the builder is attached to gets built. As far as I can tell, in IntelliJ, I can set an Ant task to trigger before or after a build, but it seems like this will be for the whole project, instead of just the relevant module that represents this Eclipse project. Is there a way I can make it only apply to a given module, or will I have to trigger it for changes to all modules?

Specifying a custom log4j.properties file for all of JUnit tests run from Eclipse

I would like to specify a specific Eclipse VM argument to all of the JUnit tests I run from Eclipse i.e.
-Dlog4j.configuration=log4j-dev.properties
This is because I want a specific log4j configuration file to be picked up by all my JUnit tests instead of the default log4j.properties file.
As of now I have to specify the above VM argument (in Run Configurations -> Arguments -> VM arguments) for each of my JUnit tests making it cumbersome because I have many tests.
You do not need to give the JVM a different property name. The logging code searches for the log4j.properties file using the classpath. So all you need to do is ensure that your test log4j.properties file is in a location that it will find before the release file.
I use Maven, which lays out files in directories to make that easy. My release log4j.properties goes in the directory src/main/resources. My test version goes in src/test/resources. The Eclipse build path (classpath) is set up to search src/test/resources before src/main/resources, so your unit tests use the test file. The JAR (or WAR) build instructions use the files from src/main/resources.
Eclipse gives you the ability to define default VM arguments that are applied to any launch which uses that VM. You could use that in your situation by defining a JRE configuration with the VM argument you want for log4j and then setting up all JUnit launches to use that JRE definition.
In Preferences, Java > Installed JREs and use the Add... button to define a JRE. In the JRE Definition dialog there is a field for Default VM arguments. Give this JRE definition a useful name such as "JDK 7 for JUnit" so that you can easily identify it.
Then in your JUnit launch(es), on the JRE tab, select the JRE definition you created.

Force Eclipse to clean a project automatically before every run

I'm looking for a solution that will force Eclipse to automatically clean a project before I run it (I'm talking about running a project using just Eclipse- no Maven, no Ant). For building I already have a Maven configuration, but sometimes I run the build directly from Eclipse as well and this is when I need that cleaning.
Shouldn't it be possible to have Maven and Eclipse use different class folders, e.g. /target for the Maven build and /bin for the Eclipse internal Java compiler? If so, you should be able to have 2 different launch configurations running the code from 2 different locations.
Second alternative: You can create a small Ant script to clear the target directory. That Ant script can be run from inside Eclipse, so a workaround is running the Ant launch configuration first and your Java launch configuration afterwards. To make this a one-step process, please install the launch groups feature from Eclipse CDT (you only need that small feature, not the whole CDT!), then you can create a "batch" like launch configuration from the other two launch configurations. Now everything is inside Eclipse with a single launch configuration!

Running only certain junit tests in a project by file name

So i have an eclipse project, with a bunch of junit test files. I want to run all of them, except ones that have a certain suffix (or inversely, only those that have one of a set of suffixes).
Eg, i can do this in maven; i can run all tests in a project that are in files that end in "Test", and all other files are ignored.
I want to do something similar in eclipse w/o having to configure things; just based on names. Right now i would go to "run configurations.." and then select "run all tests in a selected project..", but it'll run everything it finds in there; i want to omit files based on their suffix.
Is there a way to do this in eclipse?
There are several options:
Use cpsuite
Exclude them from your build path
Create a test suite like this or this