Assuming that I have a set of source folders in an Eclips project:
MyProject
base/src/impl
base/src/test
common/src/api
common/src/test
common/src/junit
Note that these are not packages, they are source folders, inside each one there's a package hierarchy, which can be just the same. Let's say if I have a class com.foo.myproject.DoSomething in the base/src/impl folder, I might have a Test called com.foo.myproject.DoSomethingTest in the base/src/Test folder, and maybe com.foo.myproject.DoSomethingUnitTest in another source folder under same package hierarchy.
What I need to do, is run all tests that are under certain source folders. Maybe all that are in a junit folder, but none from the test folder.
This works fine from Ant with the junit search patterns, for example:
<include name="**/src/junit" />
However, I want to be able to have exactly the same run configurations from Eclipse without having to call Ant. Since there are already many projects, packages and thousands of Test Classes, I am looking for a "lazy" way to get this done, that means, without having to change project structures or having to mantain complex test suites.
One Approach I have tried is to use the org.springframework.core.io.support.PathMatchingResourcePatternResolver
used by ClasspathSuite, but looking for resources in classpath always looks at the merged source folders in one single classes location, so I am not able to filter anymore at the level I intend to do it.
I am looking for two ways of doing it:
1. Filter using some TestSuite
2. Filter using some JUNIT Runner Plugin in Eclipse (is there any that can do what I need?)
Thanks!
You can right-click the source folder, and select Run As> JUnit Test.
This will run the unit tests in this source folder only.
Alternatively, when editing the Run Configuration, you can select
Run all tests in the selected project, package or source folder:
Press search
and select the folder you wish to run the unit tests of.
See "Customizing a Test Configuration" on Writing and Running JUnit tests of the Eclipse Help.
Same page describes how to create a custom Test Suite using the New Test Suite wizard.
Here is a project that seems to make what you want:
ClasspathSuite
Look for "Classpath Property Annotation" in order to set a folder from where the tests are taken.
Besides, if your test classes are really named as they seam to (all Unit Tests classes have the suffix UnitTest), then you could also use the @ClassnameFilters
annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With