Well, after a good amount of man-hours wasted, I stumbled upon the solution. More or less...
This post pointed me in the direction, more specifically the quote
To recap, MyCustomException was thrown at very early stage of test execution. The dll that contained it was not loaded yet so Unit Test Adapter indeed could not reach it.
I use a custom base class to initialize my UnitTests that need database connections. This base class has a normal constructur that does not have ClassInitialize
, because [ClassInitialize] is not called by the UnitTestAdapter when it's in subclasses:
public DatabaseAware()
{
XmlConfigurator.Configure();
_logger.Info("Configuring NHibernate");
_configuration = new Configuration().Configure();
_sessionFactory = _configuration.BuildSessionFactory();
}
So, upon invoking the constructor, if anything goes wrong, the execution of everything is apparently halted.
Curiously enough, this includes loading assemblies. So, by the time my constructor threw an Exception, the Assembly for NHibernate
was not yet loaded, resulting in a Type is not resolved for member NHibernate.HibernateException
message.
What a ride. Basically, all I did now is to introduce an exception handling in the constructor to fail if anything goes wrong:
public DatabaseAware()
{
XmlConfigurator.Configure();
try
{
_logger.Info("Configuring NHibernate");
_configuration = new Configuration().Configure();
_sessionFactory = _configuration.BuildSessionFactory();
}
catch (Exception ex)
{
_logger.Fatal(ex);
Assert.Fail(ex.Message);
}
}
Now, I can run the tests as before without any problems. (Or, at least, when a problem occurs in the constructor, I will be notified of it).