Closed
Description
With the following tests in test container, I expect one test to pass, and another to fail because of the incorrect type of the variable with ValuesAttribute.
[Test]
public void ThisOnePasses()
{
}
[Test]
public void ThisOneFails([Values("apple")] int value)
{
}
For the different NUnit package versions, behaviour is different.
3.10.0 - console message is ok, test report is correct.
Determining projects to restore...
All projects are up-to-date for restore.
nunit-sample -> /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll
Test run for /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Failed ThisOneFails("apple") [15 ms]
Error Message:
System.ArgumentException : Object of type 'System.String' cannot be converted to type 'System.Int32'.
Stack Trace:
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(StackAllocedArguments& stackArgs, ReadOnlySpan`1 parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at NUnit.Framework.Internal.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)
Failed! - Failed: 1, Passed: 1, Skipped: 0, Total: 2, Duration: - /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll (net6.0)
3.13.1 - console message is ok, test report is incorrect (no test actually run).
Determining projects to restore...
All projects are up-to-date for restore.
nunit-sample -> /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll
Test run for /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Setup failed for test fixture nunit_sample.Tests
An exception was thrown while loading the test.
System.ArgumentException: apple is not a valid value for Int32. (Parameter 'value')
---> System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo)
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
--- End of inner exception stack trace ---
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at NUnit.Framework.Internal.ParamAttributeTypeConversions.TryConvert(Object value, Type targetType, Object& convertedValue)
at NUnit.Framework.Internal.ParamAttributeTypeConversions.GetData(Object[] data, Type targetType)
at NUnit.Framework.Internal.ParamAttributeTypeConversions.ConvertData(Object[] data, Type targetType)
at NUnit.Framework.ValuesAttribute.GetData(IParameterInfo parameter)
at NUnit.Framework.Internal.Builders.ParameterDataSourceProvider.GetDataFor(IParameterInfo parameter)
at NUnit.Framework.CombiningStrategyAttribute.BuildFrom(IMethodInfo method, Test suite)
at NUnit.Framework.Internal.Builders.DefaultTestCaseBuilder.BuildFrom(IMethodInfo method, Test parentSuite)
at NUnit.Framework.Internal.Builders.NUnitTestFixtureBuilder.BuildTestCase(IMethodInfo method, TestSuite suite)
at NUnit.Framework.Internal.Builders.NUnitTestFixtureBuilder.AddTestCasesToFixture(TestFixture fixture, IPreFilter filter)
at NUnit.Framework.Internal.Builders.NUnitTestFixtureBuilder.BuildFrom(ITypeInfo typeInfo, IPreFilter filter)
at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildFrom(ITypeInfo typeInfo, IPreFilter filter)
No test is available in /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:<pathToCustomAdapters>.
3.13.2, 3.13.3 - console message is misleading, test report is incorrect (no test actually run).
Determining projects to restore...
All projects are up-to-date for restore.
nunit-sample -> /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll
Test run for /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in /Users/gp/src/test-allure/src/nunit-sample/bin/Debug/net6.0/nunit-sample.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:<pathToCustomAdapters>.