views:

256

answers:

4

Hello All

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?

A: 

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.

S.Lott
Hi I just clarified the question, this is not for testing the webservice, I just retrieve classes from it.
Neil Foley
I hate mocks. It's usually twice the work of creating the web service in the first place, and you end up spending all your debugging time trying to find out if the bug is in the web service or the mock.
Paul Tomblin
@Paul Tomblin: Right and Wrong. It's supposed to be more work. If your mock requires a lot of debugging then you didn't understand the thing you were mocking well enough. If the web service is poorly defined, then, that's par for the course. Debugging the mock is usually simpler than debugging the application, so it evens out in the long run. More up-front time to build the mock. Less ongoing to debug.
S.Lott
+1  A: 

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.

Paul Wagland
+1  A: 

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.

Karussell
To me, the task is more build automation then continuous integration. hudson is a good advice but I'd use maven (or ant) first and use hudson to execute the build scripts (end enjoy the great web based reports :) )
Andreas_D
What does "sth" mean?
S.Lott
A: 

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.

pgras