0

I am using com.sun.codemodel.JCodeModel to generate almost 1000 classes with associated JUnits for each one.

I also generate a JUnit Test Suite that executes the individual JUnit test cases.

To complete this code generation project i want to execute the JUnit test suite programmatically using final Result result = JUnitCore.runClasses(AllTests.class);.

The difficulty i am having is that the execution of the JUnit Test Suite is not synchronised to the code generation. I need to be able to detect when com.sun.codemodel.JCodeModel.build() method has completed my code generation and only then execute the JUnit Test Suite.

How can I know when com.sun.codemodel.JCodeModel.build() method completes?

Hector
  • 4,016
  • 21
  • 112
  • 211

1 Answers1

2

extend your class by JCodeModel and then override the build method:

@override
... build(){
super.build();
startTest();
}

then it should start after build function is finished.

Izu
  • 235
  • 1
  • 5
  • thanks for your suggestion. However this doesnt resolve my issue as not only do i need to wait till all the generated classes are built, i also need them to have been compiled. I am executing this project within eclipse; its starting to look like i either need to refersh the eclipse project programatically (and wait or that to complete) or just give up and run the test suite manually – Hector Sep 10 '14 at 08:55
  • 1
    You could start the compiler manually ... JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); compiler.run(null, null, null, sourceFile.getPath()); – Jan Galinski Sep 10 '14 at 15:15