开发者

Generating Unit Tests Automatically

开发者 https://www.devze.com 2022-12-17 20:40 出处:网络
I have a web tool which when queried returns generated Java classes based upon the arguments in the URL.

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 bu开发者_开发问答t is there and standard solution / approach for this?


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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消