Neil Foley
Neil Foley

Reputation: 1773

Generating Unit Tests Automatically

I have a web tool which when queried returns generated Java classes based upon the arguments in the URL.

The classes we retrieve from the webserver change daily and we need to ensure that they still can process known inputs.

Note these classes do not test the webserver, they run locally and transform xml into a custom format. I am not testing the webserver.

These classes must then be placed in specific package structure compiled and run against a known set of input data and compared against known output data.

I would like to do this automatically each night to make sure that the generated classes are correct.

What is the best way to achieve this?

Specifically whats the best way to:

  1. retrieve the code from a webserver and place it in a file
  2. compile the code and then call it

I'm sure a mix of junit and ant will be able to achieve this but is there and standard solution / approach for this?

Upvotes: 5

Views: 1978

Answers (4)

Karussell
Karussell

Reputation: 17375

You have the same goal as continuous integration ;-)

Maybe a bit overkill for this simple task, but this is the standard way to get something, compile something and test something regularly.

E.g. you could try hudson.

Upvotes: 2

pgras
pgras

Reputation: 12780

Can you only test the generated classes after they were published on the webservice ? You have no way to test during or just after the generation ?

One idea, if the generated code isn't to complex, is to load it via the GroovyClassLoader and to run your tests against it. See this page for examples.

Upvotes: 0

Paul Wagland
Paul Wagland

Reputation: 29179

First up, to answer your question: No, I do not think that there is a standard approach for this. This sounds like quite an unusual situation ;-)

Given that, what I would do is to write your JUnit tests to all call a class GeneratedCode, and then, once you download the code, rename the class to GeneratedCode, compile, and run your unit tests.

Upvotes: 2

S.Lott
S.Lott

Reputation: 392040

You should be creating a "mock" interface for your web service that (a) behaves the same way and (b) returns a known answer.

You should then do some other integration testing with the live web service where a person looks at the results and decides if they worked.

Upvotes: 0

Related Questions