TestLoader.Load fails when run under Unity's web-player

Bug #742625 reported by Damyan Pepper
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnitLite
Fix Released
Low
Charlie Poole

Bug Description

Unity's web-player runs in a restricted environment, specifically one where System.Reflection.Assembly.GetName() is not available. See http://unity3d.com/support/documentation/ScriptReference/MonoCompatibility.html

This means that NUnitLite.Runner.TestLoader.Load fails when it tries to get the assembly name. Modifying the code to look like this is a possible work around:

        public static ITest Load(Assembly assembly)
        {
            TestSuite suite = new TestSuite(GetAssemblyName(assembly));

            foreach (Type type in assembly.GetTypes())
            {
                if (IsTestFixture(type))
                    suite.AddTest(new TestSuite(type));
            }

            return suite;
        }

        private static string GetAssemblyName(Assembly assembly)
        {
            try
            {
                return assembly.GetName().Name;
            }
            catch (System.MethodAccessException)
            {
                return assembly.FullName;
            }

            return "<assembly>";
        }

Related branches

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 742625] [NEW] TestLoader.Load fails when run under Unity's web-player

Seems like a reasonable fix for this one case. However, it may be that
we could need
a special build for Unity in the future. I invite you to bring it up
on the nunit-discuss
mailing list if it seems like something we should get into.

Charlie

On Fri, Mar 25, 2011 at 10:06 AM, Damyan Pepper
<email address hidden> wrote:
> Public bug reported:
>
> Unity's web-player runs in a restricted environment, specifically one
> where System.Reflection.Assembly.GetName() is not available.  See
> http://unity3d.com/support/documentation/ScriptReference/MonoCompatibility.html
>
> This means that NUnitLite.Runner.TestLoader.Load fails when it tries to
> get the assembly name.  Modifying the code to look like this is a
> possible work around:
>
>        public static ITest Load(Assembly assembly)
>        {
>            TestSuite suite = new TestSuite(GetAssemblyName(assembly));
>
>            foreach (Type type in assembly.GetTypes())
>            {
>                if (IsTestFixture(type))
>                    suite.AddTest(new TestSuite(type));
>            }
>
>            return suite;
>        }
>
>        private static string GetAssemblyName(Assembly assembly)
>        {
>            try
>            {
>                return assembly.GetName().Name;
>            }
>            catch (System.MethodAccessException)
>            {
>                return assembly.FullName;
>            }
>
>            return "<assembly>";
>        }
>
> ** Affects: nunitlite
>     Importance: Undecided
>         Status: New
>
> --
> You received this bug notification because you are a member of NUnitLite
> Developers, which is the registrant for NUnitLite.
> https://bugs.launchpad.net/bugs/742625
>
> Title:
>  TestLoader.Load fails when run under Unity's web-player
>

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Fixed by using Assembly.FullName in all cases.

Changed in nunitlite:
importance: Undecided → Low
assignee: nobody → Charlie Poole (charlie.poole)
status: New → Fix Committed
Changed in nunitlite:
milestone: none → 0.7
Changed in nunitlite:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.