# Best practice: Api test with several versions of client

**URL:** <https://discuss.gradle.org/t/best-practice-api-test-with-several-versions-of-client/5721>\
**Category:** Old Forum Archive\
**Created:** [February 12, 2014, 5:22pm UTC](https://discuss.gradle.org/t/best-practice-api-test-with-several-versions-of-client/5721 "2014-02-12T17:22:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![karljohan\_karlberg](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@karljohan\_karlberg](https://discuss.gradle.org/u/karljohan_karlberg)\
**Post date:** [February 12, 2014, 5:22pm UTC](https://discuss.gradle.org/t/best-practice-api-test-with-several-versions-of-client/5721/1 "2014-02-12T17:22:00Z")

</div>

I have a RESTful service that is used during deploy. I hit the service by fireing off a small java program from the buildscript (this is bundled in a jar). Easy enough. I am about to do some refactoring on the api and I want to make sure I remain backward compatible on the server side…

Currently I run an integration test on my service that pulls a specific version of the “client jar” and I run what the main class would run and make some asserts. Still simple… Now I refactor the api and make changes in the client jar to use all the new fancy features. I now want to add more tests using the new fancy client jar while keeping the old one…

I can keep the tests in different source sets and hand pick the different cilent jars to each configuration but sooner or later I just have lots and lots of directories 🙂

I can keep the old impl and just add new code in the client and call a different main and different set of methods, but that leaves old dirty code in the client…

The client jar will move from version 1.x to 2.x…

Any ideas?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 13, 2014, 1:09am UTC](https://discuss.gradle.org/t/best-practice-api-test-with-several-versions-of-client/5721/2 "2014-02-13T01:09:00Z")

</div>

It’s a little bit hard to extract your requirements at this abstract level.

Perhaps try proposing some potential Gradle build script, even if it’s pseudo code in parts, then highlighting what you either don’t know how to do or what you’re not happy with.

---

<div class="post-metadata">

**Author:** ![karljohan\_karlberg](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@karljohan\_karlberg](https://discuss.gradle.org/u/karljohan_karlberg)\
**Post date:** [February 13, 2014, 6:22pm UTC](https://discuss.gradle.org/t/best-practice-api-test-with-several-versions-of-client/5721/3 "2014-02-13T18:22:00Z")

</div>

Thanks for the quick response.

Here is a quick example of what I can do (pseudo code)

```gradle
configurations {
  integ_1_0 extends testRuntime
  integ_2_0 extends testRuntime
}
  //and similar source sets...
  dependecies {
...
  integ_1_0 'autoconf:autoconf:1.0'
  integ_2_0 'autoconf:autoconf:2.0'
}
ingeg_1_0test (type: Test) {
  compileClasspath = configurations.integ_1_0.asPath
}
  ingeg_2_0test (type: Test) {
  compileClasspath = configurations.integ_2_0.asPath
}

```

duplication delux 🙂

Assume that I want to test against all trusted versions of my small helper jar I might want to do something similar to:

```gradle
foreach version of dependant jar
{ jar ->
  executeTestclassOfVersion(jar.version)
}

```

My groovy skills need improvment for sure…

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 17, 2014, 1:32am UTC](https://discuss.gradle.org/t/best-practice-api-test-with-several-versions-of-client/5721/4 "2014-02-17T01:32:00Z")

</div>

So what you have there is the general approach I would follow.

Are you unsure how to factor this repetition out into a method like ‘executeTestclassOfVersion’?
