Loading...

nunit-discuss@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [nunit-discuss] Re: Nunit testing and XNA, FileNotFound problem Charlie Poole Sun Feb 27 20:00:30 2011

Will,

It sounds like you need some basic info about how .NET works. We
can't really give you much along those lines here but the short
version is...

Your cs files create assemblies... either dlls or exes. Each
VS project creates an assembly.

Your tests might be in a separate test assembly or in the same
assembly as your game, depending on how you have it set up.

The assembly you want to load into NUnit is in the bin folder,
which is called the Output directory in the VS docs.

It seems you want to locate some file which is also in the bin
folder. Is that correct?

You would be best served by making a simple test, like just
asserting that 2+2 equals 4, and making sure you can load
and run that before going back to your original problem.

Hope this helps.

Charlie

On Sun, Feb 27, 2011 at 7:26 PM, William Tuttle <[EMAIL PROTECTED]> wrote:
> So, the the test.cs file that runs the test is at the top of the path
> with all the other .cs files, the
> file trying to load the image is MenuManager.cs. So would I be looking
> in the bin or obj folder? Am I looking for a .dll?
>
>
>
> On Feb 27, 5:18 pm, Charlie Poole <[EMAIL PROTECTED]> wrote:
>> Hello Will,
>>
>> The NUnit assemblies have nothing to do with it. It's the assembly
>> that contains the code you are writing to access content that we're
>> concerned with. Is this your test assembly? Where is the content
>> with respect to that assembly?
>>
>> Charlie
>>
>> On Sun, Feb 27, 2011 at 5:00 PM, William Tuttle <[EMAIL PROTECTED]> wrote:
>> > Ok, thanks. I'm not quite sure how to go about that. The x86-> Debug
>> > folder has the Nunit.framework.dll and a build of the content folder.
>> > So if I use the function from the second post what would I have to do
>> > to reach the files in the content folder? Do I just need to set
>> > content = to a certain path tree or is there more to it?
>>
>> > thanks,
>>
>> > Will
>>
>> > On Feb 27, 4:27 pm, Charlie Poole <[EMAIL PROTECTED]> wrote:
>> >> Although you haven't said, I'm assuming that the file you are trying to 
>> >> find is
>> >> located in the same directory as the assembly you are testing.
>>
>> >> The code below uses GetEntryAssembly(), which would return the
>> >> initial assembly that started your process (that is NUnit.exe) or null,
>> >> depending on where it is called.
>>
>> >> In your second post, you used GetExecutingAssembly(), which will
>> >> (obviously) return the currently executing assembly. If the file you
>> >> want is in the same directory as the current assembly, then that's
>> >> the way you want to go.
>>
>> >> Creating a Uri based on the assembly Codebase is the correct way
>> >> to go. The Uri's LocalPath property will give you a file system path
>> >> to the file containing the assembly. From there on it's just normal
>> >> file path manipulation.
>>
>> >> Charlie
>>
>> >> On Sun, Feb 27, 2011 at 3:35 PM, William Tuttle <[EMAIL PROTECTED]> wrote:
>> >> >    *
>>
>> >> > Nunit testing and FileNotFound
>> >> > Reply Quote Edit
>> >> > So I'm sure this has come up for anyone who was wanted to (or forced
>> >> > by a Prof) to use the Nunit testing framework with XNA. While trying
>> >> > to test certain classes I constantly get errors reporting that an
>> >> > asset from the content could not be found, like an image file.
>> >> > Apparently Nunit isn't looking in right place when it makes it shadow
>> >> > copy of the assembly. Another poster mentioned setting the content
>> >> > manager like this:
>>
>> >> >  Uri codeBaseUri = new
>> >> > Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase);
>> >> >            content = new ContentManager(myGame.Services,
>> >> > System.IO.Directory.GetParent(codeBaseUri.AbsolutePath).FullName);
>>
>> >> > I put that it my test file but Nunit gave me this error for the first
>> >> > line above:
>>
>> >> > SetUp : System.NullReferenceException : Object reference not set to an
>> >> > instance of an object.
>>
>> >> > I put this code in the [setup] function right after constructing a
>> >> > game object.
>>
>> >> > I'm pretty certain I have all the right libraries being used so I'm
>> >> > not sure why codeBaseUri would be null. Although I'm not really
>> >> > certain what a URI is either.
>>
>> >> > does anybody know a way around this?
>>
>> >> > thanks,
>>
>> >> > Will
>>
>> >> > namespace MyGame
>> >> > {
>> >> >    [TestFixture]
>> >> >    class GameTest
>> >> >    {
>> >> >        controlManager controlM;
>> >> >        MenuManager menuM;
>> >> >        ContentManager content;
>>
>> >> >        [SetUp]
>> >> >        public void Initialize() {
>>
>> >> >            Game1 game = new Game1();
>>
>> >> >  /*here*/   Uri codeBaseUri = new
>> >> > Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase);
>> >> >         content = new ContentManager(game.Services,
>>
>> >> > System.IO.Directory.GetParent(codeBaseUri.AbsolutePath).FullName);
>>
>> >> >            }
>>
>> >> >        }
>>
>> >> > --
>> >> > You received this message because you are subscribed to the Google 
>> >> > Groups "NUnit-Discuss" group.
>> >> > To post to this group, send email to [EMAIL PROTECTED]
>> >> > To unsubscribe from this group, send email to [EMAIL PROTECTED]
>> >> > For more options, visit this group 
>> >> > athttp://groups.google.com/group/nunit-discuss?hl=en.
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "NUnit-Discuss" group.
>> > To post to this group, send email to [EMAIL PROTECTED]
>> > To unsubscribe from this group, send email to [EMAIL PROTECTED]
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/nunit-discuss?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "NUnit-Discuss" group.
> To post to this group, send email to [EMAIL PROTECTED]
> To unsubscribe from this group, send email to [EMAIL PROTECTED]
> For more options, visit this group at 
> http://groups.google.com/group/nunit-discuss?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"NUnit-Discuss" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nunit-discuss?hl=en.