Execution Options
There are various ways to Assert your Architecture! with Architecture Rules.
Ant-Task
If you are not a Maven user, this Ant task is the the preferred means for asserting your architecture. The downside to this method of running the test, is that there is no means for you to provide any programmatic configuration - the entire configuration must be read from the configuration file. If you must use Ant, and you must provide programmatic configuration, you will need to see the next option, Ant Unit Test.
To use the Ant task, you must define the task with the taskdef directive, and then create a target to call assertArchitecture, and provide a name of the XML configuration file which you have placed in the project’s classpath.
To run with ant, you must include your own compile goal. This configuration below includes depends=”compile” within the test-architecture goal, so you need to implement that goal, or change the depends to your own goal, whatever you may have called your compile goal.
Also, you will need to point to all of the libs. If you’re an ant user, you probably have a /libs directory that you can point to.
For an up-to-date list of dependencies, see the dependencies list.
<property name="maven.repo" value="C:\dev\m2repo\"/>
<path id="class.path">
<pathelement id="test" path=".\target\test-classes"/>
<pathelement id="main" path=".\target\classes"/>
<!-- updated list of dependencies available at -->
<!-- http://72miles.com/architecturerules/dependencies -->
<pathelement id="junit"
path="${maven.repo}\junit\junit\3.8.1\junit-3.8.1.jar"/>
<!-- You must define all dependencies listed at -->
<!-- http://72miles.com/architecturerules/dependencies -->
<!-- as a pathelement such as the junit-3.8.1.jar above -->
</path>
<!-- you must define your own compile -->
<target name="compile"/>
<taskdef name="assertArchitecture"
configurationFileName
classname="com.seventytwomiles.architecturerules.ant.AssertArchitectureTask">
<classpath refid="class.path"/>
</taskdef>
<target name="assert-architecture" depends="compile">
<assertArchitecture
configurationFileName="architecture-rules.xml" />
</target>
Ant Unit Test
To run with ant, you must include your own compile goal. This configuration below includes depends=”compile” within the test-architecture goal, so you need to implement that goal, or change the depends to your own goal, whatever you may have called your compile goal.
Also, you will need to point to all of the libs. If you’re an ant user, you probably have a /libs directory that you can point to.
For an up-to-date list of dependencies, see the dependencies list.
<property name="maven.repo" value="C:\dev\m2repo\"/>
<path id="class.path">
<pathelement id="test" path=".\target\test-classes"/>
<pathelement id="main" path=".\target\classes"/>
<!-- updated list of dependencies available at -->
<!-- http://72miles.com/architecturerules/dependencies -->
<pathelement id="junit"
path="${maven.repo}\junit\junit\3.8.1\junit-3.8.1.jar"/>
<!-- You must define all dependencies listed at -->
<!-- http://72miles.com/architecturerules/dependencies -->
<!-- as a pathelement such as the junit-3.8.1.jar above -->
</path>
<!-- you must define your own compile -->
<target name="compile"/>
<target name="test-architecture" depends="compile">
<junit haltonerror="true">
<classpath refid="class.path"/>
<formatter type="brief" usefile="false"/>
<test name="com.seventytwomiles.architecturerules.ArchitectureTest"
haltonfailure="true"/>
</junit>
</target>
Maven 2
With Maven 2, you can run all your tests or, a single test.
To run a single test, define the variable test as the name of the test class that you wish to execute.
%> mvn -Dtest=ArchitectureTest test
To run all of your tests, enter
%> mvn test
Maven 1
With Maven 1, you can run all your tests or, a single test.
To run a single test, define the variable testcase as the name of the test class that you wish to execute.
%> maven -Dtestcase=ArchitectureTest test:single
To run all of your tests, enter
%> maven test:test