Skip to content

How to integrate it in your project

marccarre edited this page Dec 20, 2012 · 13 revisions

There are many ways to integrate CassandraUnit in your project

  1. If you are using Maven, CassandraUnit releases are available in Maven central repository. So you can just edit your pom.xml and add this test dependency:

     <dependency>
     	<groupId>org.cassandraunit</groupId>
     	<artifactId>cassandra-unit</artifactId>
     	<version>1.1.1.2</version>
     	<scope>test</scope>
     </dependency>
    

Snapshots are available too by declaring a maven repository with this url : https://oss.sonatype.org/content/repositories/snapshots/

  1. You can get jar at this url : Maven repository download

  2. You can build it : To build it you need to have an installation of maven version >=2.x You have to :

    • Clone the git repository from a tag to get a special version or from master if your want to get on top of it.
    • execute at the source home directory (where there is the pom.xml) : mvn package

Important note about Cassandra and Hector' versions

CassandraUnit comes with its own version of cassandra-all and hector-core, as of 1.1.1.2, respectively 1.1.5 and 1.1-1. In case you want to use some other versions of these dependencies:

  • put the versions you want to use in your classpath, if you use Maven, using regular Maven dependencies;
  • exclude cassandra-all and hector-core from CassandraUnit, if you use Maven add exclusions on cassandra-unit;
  • ensure there are no other conflicting dependencies, if you use Maven, using mvn dependency:analyze.

WARNING: Conflicting JARs in your classpath may result in occurrences of NoSuchMethodException when you run your tests. See also this post.

Example:

<dependency>
    <groupId>org.hectorclient</groupId>
    <artifactId>hector-core</artifactId>
    <version>1.1-2</version>
</dependency>
<dependency>
    <groupId>org.apache.cassandra</groupId>
    <artifactId>cassandra-all</artifactId>
    <version>1.1.7</version>
</dependency>

<!-- Exclude cassandra-all and hector-core to instead use the versions -->
<!-- declared above. -->
<dependency>
    <groupId>org.cassandraunit</groupId>
    <artifactId>cassandra-unit</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.cassandra</groupId>
            <artifactId>cassandra-all</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.hectorclient</groupId>
            <artifactId>hector-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- cassandra-all uses 1.6 while cassandra-unit uses 1.9, hence potential -->
<!-- occurrences of NoSuchMethodException when running tests. -->
<!-- As 1.9 is backward compatible with 1.6, the below does NOT conflict -->
<!-- with cassandra-all and can be safely added to avoid exceptions. -->
<dependency>
    <groupId>org.yaml</groupId>
    <artifactId>snakeyaml</artifactId>
    <version>1.9</version>
    <scope>test</scope>
</dependency>