Reputation: 651
I'm trying to add some tests to a project that ensure that our internal BizTalk schemas continue to correctly (in)validate some XML test files that don't meet our business rules.
Normally I would use the path to the XML and XSD files, however, since the XSD is part of a BizTalk project and the BuildAction
is "BtsCompile", the file cannot be set to copy locally. I know I can use the path to the source file (this is working for me at the moment), however, this feels like a hack because the path could change for different environments, and might not even be present in some cases (ex: CI/CD).
How can I use the schema by type (ex: MyProject.Namespace.MySchema()
) or by XML namespace (ex: http://myurl.com/schemas/MySchema
) to validate a sample XML file?
If it matters, my schemas are in a BizTalk project, and my tests are in a separate Unit Test project. I'm using Visual Studio 2013 at the moment.
Upvotes: 0
Views: 134
Reputation: 11040
I'm going to give you a frame challenge Answer here.
How to unit test an XSD schema...
You don't. Meaning, don't bother. You will spend more time setting up for unit tests than you would ever save catching a validate error in a unit test.
Why? Because if the validation error causes an actual hard error, which is not always the case, you will still have a bug, you just wasted a lot of time finding it in a unit test rather than a functionality test.
Unit tests were the popular thing a couple years ago until everyone realized the ROI is usually a net negative.
Upvotes: 0