Test generated code that includes Maven dependencies [message #1822518] |
Mon, 09 March 2020 09:32 |
Niels Heltner Messages: 6 Registered: March 2019 |
Junior Member |
|
|
Hello,
From my DSL I generate Java code which depends on libraries that are resolved through Maven (e.g. a web framework). I would like to write automated tests that test the behavior of the generated classes.
I have looked at the CompilationTestHelper class, which allows me to access the generated classes, but it does not seem like it's able to resolve Maven dependencies.
I have also looked at workbench tests, by extending the AbstractWorkbenchTest class, which seems to be able to resolve Maven dependencies by invoking 'waitForBuild()', but I can't figure out a way to get the generated classes from here.
[Updated on: Mon, 09 March 2020 09:33] Report message to a moderator
|
|
|
|
|
Re: Test generated code that includes Maven dependencies [message #1822639 is a reply to message #1822521] |
Tue, 10 March 2020 16:17 |
Niels Heltner Messages: 6 Registered: March 2019 |
Junior Member |
|
|
Karsten Thoms wrote on Mon, 09 March 2020 09:36Why don't you just simply generate the code to your Maven project and test your generated code with Unit Tests in Maven?
I'm 100% sure what you mean. My problem is that I based on a .mydsl file generate a pom.xml and Java code which depends on libraries that have to be resolved through Maven. In my tests, if I use the CompilationTestHelper class I can access and invoke the generated Java code through reflection but I cannot get Maven to resolve the dependencies.
[Updated on: Tue, 10 March 2020 16:22] Report message to a moderator
|
|
|
Re: Test generated code that includes Maven dependencies [message #1822641 is a reply to message #1822639] |
Tue, 10 March 2020 16:58 |
|
I think you try to do in a unit test what is actually an integration test. In a unit test you should not integrate with Maven, just check that the code is generated as you would like to have it.
For your Maven integration scenario create a reference project that contains DSL files just for testing, invoke the code generator within Maven and write unit tests against the generated code.
A reference project should contain a minimal consistent project with DSL files, generated and manual code. It is a stripped down version of your real project. By doing so, your generator is tested by executing it, and let the build system build what you generated.
I'd not recommend trying to resolve Maven dependencies and do other fancy stuff in your generator's unit tests. You can continue, but then without help.
|
|
|
Powered by
FUDForum. Page generated in 0.05313 seconds