Posts mit dem Label Unit Testing werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Unit Testing werden angezeigt. Alle Posts anzeigen

Montag, 30. Juli 2012

VS 2012: Can not show Test Explorer

For quite some time I was working with VS 2012 RC and everything was fine. But all of a sudden I could not open the Test Explorer. I got a MEF error message as shown below:


The main error message was

The composition produces a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information. 
1) Value cannot be null.
Paramter name: testPlatform
Followed by further error messages. I tried to repair Visual Studio installation, installed different test platform adapters but nothing helped. I found the solution in at Stack Overflow, but very hidden down below, so I repeat it here:

Under C:\Users\Tobias\AppData\Local\Microsoft\VisualStudio\11.0\ComponentModelCache delete the Microsoft.VisualStudio.Default.cache file. That does the trick for me!

Thanks GertGregers and happy testing.

Dienstag, 5. Juni 2012

Unit Testing and static methods

Miško knew since 2008 what I stumbled about today: you have a hard time if you try to test things using static classes / members.

My case was similiar to this one:

public static class SomeFactory
{
  public ISomeObject Create() { // do nasty things such as service calls }
}

public class ThisIsWhatIWantToTest
{
  public void AMethod()
  {
    // ...
    var someObject = SomeFactory.Create();
    // ...
  }
}


I wanted to write tests for AMethod but I had a hard time. Acutally I could not manage to find a seam to work around the service call easily.

Another thing I noticed along the way is, that static things obscure the dependencies in the code. This is not a good thing because it makes the code harder to understand. If you have dependencies, the should be widely visible for the sake of clarity.

I will very carefully consider the use of statics from now.

Cheers,
Tobias.