Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing GetManifestResourceStream

Quick question about unit testing.

My application has a few embeded Xml files, they are often added and sometimes removed. I have a method that I want to unit test that contains the line

Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlFile)

where xmlFile is a parameter

Because of this the test will become dependent on a particular xml file being there, and there is a chance it could be removed at a later date, which is fine, but would break my test when really it shouldn't.

Does anybody know anyway around this dependency other than removing this line of code and passing it into the method instead (That will only mean I have to test it else where).

like image 493
mat-mcloughlin Avatar asked Mar 26 '26 07:03

mat-mcloughlin


1 Answers

Use GetManifestResourceNames(). Only run the test on the names you discover this way.

like image 111
Hans Passant Avatar answered Mar 27 '26 21:03

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!