简体   繁体   English

如何自动测试xsd和生成的类是否同步?

[英]How to test automatically that xsd and generated classes are synchronized?

I have an xml schema file and have generated classes out of that. 我有一个xml架构文件,并从中生成了类。 During development the xsd can change. 在开发过程中,xsd可以改变。 How can I make sure that the xsd and the generated classes are synchronized? 如何确保xsd和生成的类是同步的?

There is the possibility to generate the classes at build time via maven. 可以通过maven在构建时生成类。 Using this or not, I would like to be sure in a unit test. 使用与否,我想在单元测试中确定。

Thanks and greetings Steff 谢谢和问候Steff

Under which circumstances can they not be synchronized? 在哪些情况下他们不能同步? While I can imagine writing a simple JAXB plugin which would add a schema timestamp to the generated classes - so that you could compare timestamps in a unit test. 虽然我可以想象编写一个简单的JAXB插件 ,它会为生成的类添加一个模式时间戳 - 这样你就可以比较单元测试中的时间戳。

However I have doubt in the whole approach. 但是我对整个方法都有疑问。 Schema compilation is aa part of the build process and this must be flawless by design. 模式编译是构建过程的一部分,设计必须完美无缺。 You are not checking that Java files are "synchronized" with the compiled .class files, are you? 您没有检查Java文件是否与已编译的.class文件“同步”,是吗? The same should be the case for schema compilation. 模式编译也应如此。

You force the execution of the generation every build. 您强制执行每个构建的生成。 Or under a Profile not to execute it so many times and make your compilation time in development longer. 或者在一个Profile不要多次执行它,并使你的编译时间更长。

Here you can take a look at a JAXB plugin for generate the sources every time. 在这里,您可以查看JAXB插件,以便每次都生成源。

http://java.net/projects/maven-jaxb2-plugin/pages/Home http://java.net/projects/maven-jaxb2-plugin/pages/Home

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM