Can't get Unit Test to work with some projects

  • Thread starter Richard Lewis Haggard
  • Start date
R

Richard Lewis Haggard

I'm having trouble creating unit tests for some of the projects in my
solution. The unit test doesn't seem to recognize that there are classes and
methods in some of the projects in a solution and so does not give me the
opportunity to ask it to create unit tests for those project classes and
members. What's the trick?
 
S

sloan

In VS2005, classes default to

class MyClass
{

void MyMethod()
{
}

}


which means they are not available to outside assemblies.


You have to make sure you add "public" (most common) to your def



public class MyClass
{

public void MyMethod()
{
}

}




That's one guess.
 
R

Richard Lewis Haggard

Nope, not it. Good guess but that is not the issue here. Not only are the
classes public but the test wiz doesn't always get down the namespace tree
to where the class resides in the first place. This is a WPF/CAB produced
solution.

Here's an example of a class that is completely invisible to the test wiz.
This class is derived from an interface that was declared in
MyNameSpace.Application.Interface.

The project is named Application. It has a number of classes and interfaces
in it. This is one of those classes, derived from an interface which resides
in a different project, Application.Interface.

In project Application.Interface -
namespace MyNameSpace.Application.Interface
{
public interface ILTrace
{
bool WriteLine( string message );
}
}

In project Application -
using System;
namespace MyNameSpace.Application.Services
{
public class LTrace : Interface.ILTrace
{
public bool WriteLine( string message )
{
bool bReturn;
try
{
System.Diagnostics.Debug.WriteLine( message);
bReturn = true;
}
catch (Exception e)
{
bReturn = false;
}
return bReturn;
}
}
}

This compiles and executes in the desired fashion.

If I actuate VS05's menu item Test->New Test and select Unit Test Wizard
from the presented templates, it presents a Create Unit Tests form with a
number of projects populating a tree. If I open the tree item that
corresponds to the project that contains the above class I see a number of
cascading items corresponding to the namespaces that are present in the
project but this tree item list is incomplete. The root item Application has
a single child of MyNameSpace which has a single child of Application and
this child has no children. It should have had a child of Services which
should have had a child of LTrace. I should have been able to get down to a
methods sub item and then pick WriteLine as a method for which a unit test
would be generated.

I've been going around this for a couple of days and have made zero progress
on resolving the issue. I'm betting one of you wizard's out there knows what
silly little thing I've done and can correct this unworthy egg's
foolishness.
 
R

Richard Lewis Haggard

There seems to be a problem with the parsing of the namespace by the unit
test code and I'm beginning to suspect that it is related to the CAB
generation of view modules. It looks like the code is failing to parse
something in the namespace but continues on without generating a warning for
display to the developer. It appears that the unit test operates on the
source code itself and is not dependent upon extracting information via
reflection from the compiled modules. Has anyone else had unit test problems
with CAB/WPF/SCSF c# solutions and, if so, what happened and how did you fix
it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top