You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I tried to write testcases for another issue that I created, I realized it is not that easy to write test cases currently. Also there are two approaches to test cases at the moment. I would like to propose a possible take on this and would like to discuss possible improvements.
First, I spotted a couple aspects that influence the difficulty of writing tests:
the Generator class uses maven plugin specific code, e. g. MojoException
the Generator seems to do to many things to be tested easily, but testing GeneratorParser solely seems not to be enough as validating the created object structure is not our main goal
the Generator class needs a package name which makes it difficulty to test a single template class
the Generator class writes it output as file, thus we need to include the file system for testing.
Before writing some proposals, we need to maintain the core api classes as-is, including their location, so that any users are not affected. These are all annotations to define templates. From the current project structure the Generator classes are not part of the public api as the functionality is provided as maven plugin only.
From my perception we have the following blocks of functionality
annotations for describing templates
dicovery to find annotated classes within a specific scope
parser to translate annotation drive descriptions into java objects
converter to generate json templates from our java objects
validator that uses the specified json schema to verify the generated templates
export functionality to write the generated json to files
maven plugin that bundles everything together and makes these functions accessibly
I would not neccessarily say that we need to decouple of all those. From a testing perspective I would rate tests that generate templates for a specific class and verify that generated json is as expected. This would test the afore-mentioned bullets from 3 and 4 which are roughly 70% to 90% of this code base.
Obviously, it also makes sense to have a few test cases for class disovery (bullet 2) and the maven plugin (bullet 7). For the latter I am not sure if there exists utility already to test maven plugin integration. For schema validations (bulett 5), we could put some of the previously released version into the test resources and write tests as well.
To simplify writing the majority of tests, as desribed earlier containing the logic within bullets 3 and 4, we would need to achieve two things:
Extract classgraph specific types for the generation call and prefer a class as input
Instead of writing to files we should return a json string
I know this is a lot of text and also a proposal to do major changes. You also might say, bigger refactorings are not in the current scope of development. Still, I wanted to write down my thoughts and possibly discuss approaches and alternatives.
Kind regards
Alexander Skrock
The text was updated successfully, but these errors were encountered:
When I tried to write testcases for another issue that I created, I realized it is not that easy to write test cases currently. Also there are two approaches to test cases at the moment. I would like to propose a possible take on this and would like to discuss possible improvements.
First, I spotted a couple aspects that influence the difficulty of writing tests:
Generator
class uses maven plugin specific code, e. g.MojoException
Generator
seems to do to many things to be tested easily, but testingGeneratorParser
solely seems not to be enough as validating the created object structure is not our main goalGenerator
class needs a package name which makes it difficulty to test a single template classGenerator
class writes it output as file, thus we need to include the file system for testing.Before writing some proposals, we need to maintain the core api classes as-is, including their location, so that any users are not affected. These are all annotations to define templates. From the current project structure the
Generator
classes are not part of the public api as the functionality is provided as maven plugin only.From my perception we have the following blocks of functionality
I would not neccessarily say that we need to decouple of all those. From a testing perspective I would rate tests that generate templates for a specific class and verify that generated json is as expected. This would test the afore-mentioned bullets from 3 and 4 which are roughly 70% to 90% of this code base.
Obviously, it also makes sense to have a few test cases for class disovery (bullet 2) and the maven plugin (bullet 7). For the latter I am not sure if there exists utility already to test maven plugin integration. For schema validations (bulett 5), we could put some of the previously released version into the test resources and write tests as well.
To simplify writing the majority of tests, as desribed earlier containing the logic within bullets 3 and 4, we would need to achieve two things:
With these changes tests could look as simple as:
I know this is a lot of text and also a proposal to do major changes. You also might say, bigger refactorings are not in the current scope of development. Still, I wanted to write down my thoughts and possibly discuss approaches and alternatives.
Kind regards
Alexander Skrock
The text was updated successfully, but these errors were encountered: