I'm using JDepend to analyze my architecture and create structural tests to verify dependency within a Layered architecture. The two relevant layers are com.domain and com.infrastructure. Domain concretely depends on the Infrastructure layer.
Why is the following test failing?
import java.io.IOException;
import jdepend.framework.DependencyConstraint;
import jdepend.framework.JDepend;
import jdepend.framework.JavaPackage;
import junit.framework.TestCase;
public class DependencyTest extends TestCase {
private JDepend jdepend;
@Override
public void setUp() throws IOException {
jdepend = new JDepend();
jdepend.addDirectory("build/classes/com");
}
public void testDomainDependsOnInfastructure_ShouldBeTrue() {
DependencyConstraint constraint = new DependencyConstraint();
JavaPackage domainPackage = constraint.addPackage("com.domain");
JavaPackage infastructurePackage = constraint.addPackage("com.infrastructure");
domainPackage.dependsUpon(infastructurePackage);
jdepend.analyze();
assertEquals("Domain doesn't depend on Infrastructure layer", true, jdepend.dependencyMatch(constraint));
}
}
jdepend.analyze() returns the relevant packages, so I do know it is finding my code. Any ideas?
Figured it out. JDepend's match function checks all packages, including libraries. I had to custom load it with just the packages I wanted. Here's the code that resolved my problem, if anyone ever runs into this problem.