Better Exception if SetCulture attribute is applied multiple times

Bug #1082330 reported by Pascal Berger
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
Fix Released
Medium
Charlie Poole
NUnit V2
Fix Released
Medium
Charlie Poole
NUnitLite
Fix Released
Medium
Charlie Poole

Bug Description

The following exception is throw If I accidentally apply twice a SetCulture attribute to a test case. It would be nice if the exception message would point to the cause of the problem.

System.ArgumentException: An entry with the same key already exists. Server stack trace: at System.Collections.Specialized.ListDictionary.Add(Object key, Object value) at NUnit.Core.NUnitFramework.ApplyCommonAttributes(Attribute[] attributes, Test test) at NUnit.Core.Builders.NUnitTestCaseBuilder.BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms) at NUnit.Core.Builders.NUnitTestCaseBuilder.BuildFrom(MethodInfo method, Test parentSuite) at NUnit.Core.Extensibility.TestCaseBuilderCollection.BuildFrom(MethodInfo method, Test suite) at NUnit.Core.Builders.NUnitTestFixtureBuilder.AddTestCases(Type fixtureType) at NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildSingleFixture(Type type, Attribute attr) at NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildFrom(Type type) at NUnit.Core.Extensibility.SuiteBuilderCollection.BuildFrom(Type type) at NUnit.Core.TestFixtureBuilder.BuildFrom(Type type) at NUnit.Core.Builders.TestAssemblyBuilder.GetFixtures(Assembly assembly, String ns) at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites) at NUnit.Core.TestSuiteBuilder.Build(TestPackage package) at NUnit.Core.SimpleTestRunner.Load(TestPackage package) at NUnit.Core.ProxyTestRunner.Load(TestPackage package) at NUnit.Core.ProxyTestRunner.Load(TestPackage package) at NUnit.Core.RemoteTestRunner.Load(TestPackage package) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Changed in nunit-3.0:
status: New → Triaged
importance: Undecided → Medium
Changed in nunitlite:
status: New → Triaged
importance: Undecided → Medium
Changed in nunitv2:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Charlie Poole (charlie.poole) wrote :

This is due to the fact that SetCultureAttribute is allowed multiple times in order to provide for a future extension whereby the test might be run multiple times under different cultures. In fact, the implementation may change to using a single attribute with multiple, comma-separated cultures.

For NUnit 2.x and NUnitLite, the simple solution is to not allow multiple occurrences of the attribute. For NUnit 3.0, we could do that at first but then implement the preferred solution of running multiple times.

Charlie

Revision history for this message
Simone Busoli (simone.busoli) wrote :

I'd suggest that in 3.0 the attribute is changed to not allow multiple instances then, which will break at compile time rather than runtime.

Revision history for this message
Adam Connelly (adam-rpconnelly) wrote : Re: [Bug 1082330] Re: Better Exception if SetCulture attribute is applied multiple times
Download full text (3.1 KiB)

My 10 cents.

I'd find it more natural if the behaviour was changed so that applying
it multiple times caused the test to be run multiple times, once for
each test.

The reason I say this is I'm sure I saw Charlie mentioning comma
separating the list of cultures. That's fair enough, but if you can
apply the attribute multiple times, you don't need to know that to run
the test for multiple cultures you need to comma separate the
arguments.

On 23 Nov 2012, at 17:40, Simone Busoli <email address hidden> wrote:

> I'd suggest that in 3.0 the attribute is changed to not allow multiple
> instances then, which will break at compile time rather than runtime.
>
> --
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
> https://bugs.launchpad.net/bugs/1082330
>
> Title:
> Better Exception if SetCulture attribute is applied multiple times
>
> Status in NUnit Test Framework:
> Triaged
> Status in NUnitLite Testing Framework:
> Triaged
> Status in NUnit V2 Test Framework:
> Triaged
>
> Bug description:
> The following exception is throw If I accidentally apply twice a
> SetCulture attribute to a test case. It would be nice if the exception
> message would point to the cause of the problem.
>
> System.ArgumentException: An entry with the same key already exists.
> Server stack trace: at
> System.Collections.Specialized.ListDictionary.Add(Object key, Object
> value) at NUnit.Core.NUnitFramework.ApplyCommonAttributes(Attribute[]
> attributes, Test test) at
> NUnit.Core.Builders.NUnitTestCaseBuilder.BuildSingleTestMethod(MethodInfo
> method, Test parentSuite, ParameterSet parms) at
> NUnit.Core.Builders.NUnitTestCaseBuilder.BuildFrom(MethodInfo method,
> Test parentSuite) at
> NUnit.Core.Extensibility.TestCaseBuilderCollection.BuildFrom(MethodInfo
> method, Test suite) at
> NUnit.Core.Builders.NUnitTestFixtureBuilder.AddTestCases(Type
> fixtureType) at
> NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildSingleFixture(Type
> type, Attribute attr) at
> NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildFrom(Type type) at
> NUnit.Core.Extensibility.SuiteBuilderCollection.BuildFrom(Type type)
> at NUnit.Core.TestFixtureBuilder.BuildFrom(Type type) at
> NUnit.Core.Builders.TestAssemblyBuilder.GetFixtures(Assembly assembly,
> String ns) at NUnit.Core.Builders.TestAssemblyBuilder.Build(String
> assemblyName, Boolean autoSuites) at
> NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName,
> String testName, Boolean autoSuites) at
> NUnit.Core.TestSuiteBuilder.Build(TestPackage package) at
> NUnit.Core.SimpleTestRunner.Load(TestPackage package) at
> NUnit.Core.ProxyTestRunner.Load(TestPackage package) at
> NUnit.Core.ProxyTestRunner.Load(TestPackage package) at
> NUnit.Core.RemoteTestRunner.Load(TestPackage package) at
> System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
> md, Object[] args, Object server, Object[]& outArgs) at
> System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
> msg)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunit-3.0/+bug/1082330/+subsc...

Read more...

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

My intent in 3.0 is that multiple instances (and possibly comma-separated values in a single instance) should cause the test to run multiple times, using each of the cultures specified. So, [SetCulture("en-US"), SetCulture("fr-FR")] would run the test twice, once using the US English culture and once using French.

Comma-separated values are an easy alternative syntax requiring less typing.

A few added considerations...

1. For 3.0, I'd actually prefer to change the name from SetCulture to Culture, but there is already a Culture attribute with different semantics. I have a plan for this and I'll publish it for review shortly.

2. Everything stated about SetCulture also applies to SetUICulture.

3. Probably I should go ahead and apply the 2.6/nunitlite solution to 3.0 first, planning on moving to a more permanent solution later.

Charlie

Changed in nunitlite:
milestone: none → 0.9
Changed in nunitv2:
milestone: none → 2.6.3
Changed in nunitlite:
assignee: nobody → Charlie Poole (charlie.poole)
Changed in nunitv2:
assignee: nobody → Charlie Poole (charlie.poole)
Changed in nunitlite:
status: Triaged → Fix Committed
Changed in nunit-3.0:
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.9.6
Changed in nunitv2:
status: Triaged → Fix Committed
Changed in nunit-3.0:
status: Triaged → Fix Committed
Revision history for this message
Charlie Poole (charlie.poole) wrote :

A separate bug, #1093505, has been filed to cover further improvements under NUnit 3.0.

Changed in nunitlite:
status: Fix Committed → Fix Released
Changed in nunit-3.0:
status: Fix Committed → Fix Released
Changed in nunitv2:
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.