Reputation: 1608
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:
ant test-ClassA
.ClassA
it also compiles ClassC
.test
dir. In my case it would be test-ClassA
and test-ClassB
.Is it possible to achieve any of those goals with Ant? Or maybe you have better suggestions about running tests?
Upvotes: 1
Views: 58
Reputation: 5266
Make your initial changes to ClassA
non-breaking - e.g. if you're changing a method, at first make a copy of the method with a new name but leave the old method unchanged. When you have successfully developed and tested the changes, then you can change the users of ClassA
.
Upvotes: 1