5

I am creating one web application which has structure as shown in following image:

Structure

I have all entities and datastore files in the App_Code folder. i.e no separate project layer is created. I want to use Nunit for unit testing. But as for NUnit testing I need projectname.dll and my web application will not create dll I don't know how to test my methods.

If I create a separate project for unit tests, I can not reference datastore and other files in that project. Kindly suggest how can I use Nunit in this case.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1181942
  • 1,587
  • 7
  • 35
  • 45
  • 2
    you should create web application, rather than website: http://stackoverflow.com/questions/398037/asp-net-web-site-or-asp-net-web-application – cuongle Mar 07 '13 at 06:12
  • I can not do it as this is existing application and I am just adding a module to it. – user1181942 Mar 07 '13 at 06:14
  • 1
    possible duplicate of [Unit Testing ASP.net Web Site Project code stored in App\_Code](http://stackoverflow.com/questions/1198555/unit-testing-asp-net-web-site-project-code-stored-in-app-code) – Oscar Mederos Mar 07 '13 at 06:22
  • I dont know this is right or not, but I think I will have to create a separate project and all the time copy class files from website to project will work. This is bit frustrating. But I can see any other solution – user1181942 Mar 07 '13 at 06:23
  • 1
    @user1181942 I was going to suggest it. See my edit. – Oscar Mederos Mar 07 '13 at 06:26

1 Answers1

4

Please, check this: Unit Testing ASP.net Web Site Project code stored in App_Code.

You can also create another project, just for unit testing purposes. When you create it, just include all the required files (in App_Code) As a Link. That way you will be creating shortcuts, so if you modify one file in your project, the other project you created will reflect the changes.

Community
  • 1
  • 1
Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124
  • Ok so you mean, that I should create one separate project for unit tests. But in that case how tests classes can access my actual classes that contains methods? Because All methods are in website and not in project, my test class is not able to access methods to test. And when i say I need dll file means i need Projectname.dll file to use Nunit. I have edited question. – user1181942 Mar 07 '13 at 06:09
  • 1
    I thought you were talking about a `Web Application`. I should have paid more attention to your screenshot ;).. you might want to see http://stackoverflow.com/questions/1198555/unit-testing-asp-net-web-site-project-code-stored-in-app-code – Oscar Mederos Mar 07 '13 at 06:23
  • 1
    See [here](http://stackoverflow.com/a/15132039/297114) for how to add the files as a link – Oscar Mederos Mar 07 '13 at 06:30
  • I want mark this as answer...but your answer is not actual answer but your comment is..So just upvoting your comments – user1181942 Mar 07 '13 at 07:16
  • @user1181942 what comment exactly? I'll modify my answer then. – Oscar Mederos Mar 07 '13 at 07:22
  • The last one where you have given link to "add as link" and the one where you have given link to possible duplicate.. – user1181942 Mar 07 '13 at 07:31