|
Hi, I am trying to create VSTS unit tests for my ASP.NET 2.0 application classes which resides in App_Code folder. Whenever I right click on the code editor and select 'Create Unit Test' against a method in the class, the 'Create Unit Test' window does not list my method. None of the methods in my classes are displayed instead it only shows two classes 'ProfileCommon' and 'ThemeLoad'. TFS Version: B3Refresh Any one got into this situation Thanks -Praveen |

Unable to create unit tests...
karnalta
Guys, It seems to be a BUG!!
This is my scenario. I have Three folders in app_code folder. Each folder contains separate namespaces.
I found out that if I comment out namespace declaration, I can create unit tests based on these classes. If I reinstate namespace declaration, unit test window does not show the class or methods.
namespace
BusinessLogic //Comment to create Unit Tests.{
public class WithdrawalLogic{
public bool checkBalance(){}}
}
I started by adding a new class without any namespace declaration, and viewed the class in unit tests window.
OL
1. When I add <codeSubDirectories> entries in web.config, my build breaks saying the namespace cannot be resolved.
error CS0246: The type or namespace name 'DataAccess' could not be found (are you missing a using directive or an assembly reference )
2. After adding 'using' directive, I am not getting intellisense. The build fails even with 'using' directive
3. If I remove <codeSubDirectories> I see the build succeeds. But in the output window it doesn't show any status about these sub folders.
It shows status only if I declare the sub directories.
Building directory '/MyBank/App_Code/Business Logic/'. //This line does not appear if I remove <codeSubDirectories>
Any thing wierd here
This problem prevents me from setting up unit tests for the web application. I need to automate these with my build machine
What we did now is to get all class files added to a separate class library project and unit test them. This works, but I cannot automate this with my team project and in build machine.
CarlosV
Praveen
Take a look at the following MSDN topics
http://msdn2.microsoft.com/en-us/library/ms182520.aspx
http://msdn2.microsoft.com/en-us/library/ms182526.aspx
Also see the following blog:
http://blogs.msdn.com/vstsqualitytools/archive/2005/08/02/446322.aspx
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
cougar68
Ok did some checking and this is a bug. However you can work around this by listing the directory as a code directory in the web.config file. For example:
<compilation debug="false">
<codeSubDirectories>
<add directoryName="MySubDir"/>
</codeSubDirectories>
</compilation>
For more information on <codeSubDirectories> see the following MSDN link:
http://msdn2.microsoft.com/54dwfbb7.aspx
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Rockado
Hi,
Just pinging back to see if you have those extra details -- we can't repro it here, so we need some more information :)
Yours,
Dominic
AFoxmore
What language are you using
Can you post a snippet of those classes Also, make sure that you have the Create Unit tests dialog set to show Non Public Items etc -- it's on the "Filter" Button in the codegen dialog.
Glagoleva Natalia
Hello
I am not able to repro this issue on my box. However what you are doing should work. You may want to post this on the dotnet.framework.asp.net newsgroup. They should be able to track down why this does not work in your environment.
Here is how I tested.
Under my App_Code folder I have three folders. Happy, Sad, and HappySad.
Each folder has a class with a different namespace.
The class in the HappySad folder uses the classes from the Happy and Sad folders.
My ASPX page creates and calls the class from HappySad folder. My Web.Config looks like this.
<codeSubDirectories>
<add directoryName="Happy"/>
<add directoryName="Sad"/>
<add directoryName="HappySad"/>
</codeSubDirectories>
Everything build with no errors and I get intellisence in my HappSad class when I use either Happy or Sad classes.
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Koen Verschueren
And what about such situation
Happy\Happy.cs:
using namespase Sad;
namespace Happy
{
// code
}
Sad\Sad.cs:
using namespase Happy;
namespace Sad
{
// code
}
HarmonicSoftware
I got it resolved by changing the order of declaring sub directories in web.config.
<
codeSubDirectories><
add directoryName="Base Classes"/><
add directoryName="Data Access"/><
add directoryName="Business Logic"/></
codeSubDirectories>{'Business Logic' calls 'Data Access'}
The order does matter! If I put Data Access after Business Logic, build fails
Still, Olega's situation is valid...
Brian
ChuckD_Duncan
Ok I now see what you are doing. I was able to repro this with ASP.Net app. It appears that Unit test with ASP.Net does not pickup other namespaces. However Unit test for Windows or ClassLib project will pick up other namespaces just fine. I will do some checking to see if there is anything you can do other then creating a wrapper class and using that for the unit test.
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
EB78
OK. Your work around works for Unit Tests. But it broke my namespace reference when building original web application.
namespace
BusinessLogic //Comment this to unit test{
public class WithdrawalLogic{
public bool checkBalance(string accountNumber, string withdrawAmount){
bool balanceInfo = false;DataAccess.AccountModify getBalance =
new DataAccess.AccountModify();.......
}
}
}
Here from 'BusinessLogic' namespace, I can't use objects from 'DataAccess' which is another namespace (Also one folder per namespace)
After removing <codeSubDirectories>, the build is OK but not unit tests.
-Praveen
astanley
Hello
I am not sure what you mean by "But it broke my namespace reference when building original web application."
Are you getting build errors if so what are they My web site project builds fine using a folder per namespace and listing all my folders with a <codeSubDirectories> in my config file.
If you add a using statement for the other namespaces do you get intellisence when you try and use classes from the other namespaces
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.