I have a java project and i'm trying to do TDD.
My problem is when I'm about to change API of one class, I edit its tests, then the class itself. But there might be a bunch of other classes using the first class I edited.
So I would like compile this one class and its dependecies only. And then run the tests in such minimal environment.
Here's an example. My project structure prototype:
.
|_ build.xml
|_ lib/
| |_ *.jar
|_ src/
| |_ myPackage/
| |_ ClassA.java
| |_ ClassB.java
| |_ ClassC.java
|_ test/
|_ myPackage/
|_ ClassATest.java
|_ ClassBTest.java
ClassA
uses ClassC
. ClassA.java
:
import myPackage.ClassC;
...
Now after the API changes in ClassA
I would like to run its tests, but without compiling ClassB
. So I want to compile only ClassA
and ClassC
.
I'm using Ant for builds. I found a similar answer in here. But in this case I have to manually specify which classes to compile:
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath">
<include name="src/myPackage/ClassA.java"/>
<include name="src/myPackage/ClassC.java"/>
</javac>
My goals are:
- Be able to run all tests separately. E.g.
ant test-ClassA
. - Make Ant automatically resolve dependencies. Meaning, when I build tests for
ClassA
it also compilesClassC
. - Make Ant to build test targets automatically for every test suite in
test
dir. In my case it would betest-ClassA
andtest-ClassB
.
Is it possible to achieve any of those goals with Ant? Or maybe you have better suggestions about running tests?