简体   繁体   中英

When does a unit test load dependent assemblies?

I need to better understand when assemblies are loaded for Unit Testing.

I have a class ( ClassDerived ) that I am Unit Testing. ClassDerived is derived from another class ( ClassBase ).

I am attempting to use the ClassInitialize attribute to initialize ClassDerived before running the first test. The Unit Test project has a reference to both ClassBase and ClassDerived .

When executing the code in the ClassInitialize method, I notice that the assembly containing ClassDerived has not been loaded.

I determined this by looking at the return value from a call to GetAssemblies() .

var assemblies = System.AppDomain.CurrentDomain.GetAssemblies();

Oddly enough the assembly containing ClassBase is loaded.

I tried moving the initializing code to the Unit Test constructor with the same result.

Does anyone know what is going on?

I suspect the time-of-load is not peculiar to unit testing. In .net 3.5, here is what I've seen:

Given an assembly 'X' that has method 'Y', and method 'Y' uses something in assembly 'Z'.

In this case, assembly 'Z' will be loaded just before method 'Y' is executed. .net 4.0 supposely introduced greater 'laziness' on a number of fronts, so I don't know if the above observation is still true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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