Testing devices - using an image as a resource in a test project

One part of a project in which I write unit tests to extract data from a jpeg header.

I would like to create a unit test that checks this extraction using a known image (so I can check the known properties of this image).

It seems logical to me that this sample image is stored as a resource in the testing project, but I'm not sure how to do it. If it were a WPF project, I would just use the package syntax.

Is there any best practice for something like this (or even something that works)?

Thanks, WTS

+3
source share
2 answers

@Matthew Manela, (, , ) . , .

, .

( ):

private string GetValidFileName()
{
    FileInfo fileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
    return Path.Combine(fileInfo.DirectoryName, @"Resources\Sample.jpg");
}
+2

.
, :

Assembly.GetExecutingAssembly().GetManifestResourceStream("TestProject.TestImages.myImage.png");

.

+5

Source: https://habr.com/ru/post/1785061/


All Articles