locked
Unit Test Project Question RRS feed

  • Question

  • User1277400347 posted

    I have a weird thing happening in my MVC solution.  I added a Test Project, no problem, I then created a unit test by right clicking on code editor which then create all the stubs for the class I was in.  No problem so far... I then code up the tests using intelli-sense which worked in finding things like static objects etc.  So far so good.  But whenever I attempt to run these tests, the entire project rebuilds (should not be a problem right? But then, the build fails because it can't find a reference to the very method Intelli-sense found!

    I'm wondering if this isn't an IIS direcory secutiry issue as the project is being worked on right out of Inetpub.  In addition, we are using SVN on back-end to save solution.  It's almost as if the test project is being built before the project it's trying to test!  I've ensured that all the build configuration manager settings are identical (for all projects including the test project).  I've also ensured that the proper build order is set in the solution.  The test projects references a project (and not the dll), but just simply can't seem to find the assembly.  If I go to the test project references after the solution build (so Test Window can find all tests in solution) the reference cannot be found, even though it was just built with no errors.  I've even tried to point the test project references to the debug/bin folder to find that assembly and it can't find it, yet intelli-sense can...

    Any help would be appreciated. 

     

    Friday, September 12, 2014 12:58 PM

Answers

  • User1277400347 posted

    Found the solution to this...

      Apparently if all the "other" projects are set to use ANYCPU in the build settings, the test project itself (regardless of build configuration for that project of ANY CPU) must have the Test Setting Default properly set to X64!  Once I did this everything worked...

    To find this setting select your test project in the solution explorer, then go to the Test Tab,  then Test Settings, then Default Architecture, change it to whichever one it isn't, in my case I changed it to x64 and rebuilt the project.  This time it works, and it explains why Intell-sense works (intelli-sense uses meta-data (either PDB or reflection on class itself and NOT the assembly)...

    One other note on this : YOU will not be able to run unit tests after a compile if the solution contains projects with different .NET releases.  What happens is that the references in the test project will always show an error after a solution build!!!!!!!  There are two solutions for this depending on your environment 1) Make all the projects run the same version of .NET or 2) You have to create a "published" dll that the test project points to!!!!!!  In my mind both options are a kludge but that's the way it works.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 12, 2014 2:15 PM
  • User-1454326058 posted

    Hi v2kea60,

    You may create the MVC project with test project together when create a new project, then check it.

    Best Regards

    Starain Chen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 14, 2014 9:34 PM

All replies

  • User1277400347 posted

    Found the solution to this...

      Apparently if all the "other" projects are set to use ANYCPU in the build settings, the test project itself (regardless of build configuration for that project of ANY CPU) must have the Test Setting Default properly set to X64!  Once I did this everything worked...

    To find this setting select your test project in the solution explorer, then go to the Test Tab,  then Test Settings, then Default Architecture, change it to whichever one it isn't, in my case I changed it to x64 and rebuilt the project.  This time it works, and it explains why Intell-sense works (intelli-sense uses meta-data (either PDB or reflection on class itself and NOT the assembly)...

    One other note on this : YOU will not be able to run unit tests after a compile if the solution contains projects with different .NET releases.  What happens is that the references in the test project will always show an error after a solution build!!!!!!!  There are two solutions for this depending on your environment 1) Make all the projects run the same version of .NET or 2) You have to create a "published" dll that the test project points to!!!!!!  In my mind both options are a kludge but that's the way it works.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 12, 2014 2:15 PM
  • User-1454326058 posted

    Hi v2kea60,

    You may create the MVC project with test project together when create a new project, then check it.

    Best Regards

    Starain Chen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 14, 2014 9:34 PM