TUnit 0.3.0 has broken my test code #1242
-
Hello everybody, I have converted all my test code from Here is an example of what doesn't work: The base class for all my JSON values is defined as: public abstract class JsonValue To test casting to a public static IEnumerable <JsonValue> InvalidCastValues () =>
[
new JsonArrayValue (null),
new JsonDateValue (null, Date.Today ()),
new JsonDateTimeValue (null, DateTime.Now),
new JsonDoubleValue (null, 0.0),
new JsonInt32Value (null, 0),
new JsonInt64Value (null, 0),
new JsonObjectValue (new JsonInt32Value ("a", 0))
];
[Test]
[MethodDataSource (nameof (InvalidCastValues))]
public async Task Cast_FromInvalidValue (
JsonValue json
) =>
await Assert.That (() => _ = (Boolean) json).ThrowsExactly <ArgumentException> (); This code compiles well with
I've tried to change the data source method to the following, but I still have compilation errors: public static IEnumerable <Func <JsonValue>> InvalidCastValues () =>
[
static () => new JsonArrayValue (null),
static () => new JsonDateValue (null, Date.Today ()),
static () => new JsonDateTimeValue (null, DateTime.Now),
static () => new JsonDoubleValue (null, 0.0),
static () => new JsonInt32Value (null, 0),
static () => new JsonInt64Value (null, 0),
static () => new JsonObjectValue (new JsonInt32Value ("a", 0))
];
And also errors in the test method. I've also tried to use I'm currently out of ideas to make this work. Does somebody knows what's wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
Sounds like a bug in a recent refactor @Patrick8639. Could you produce me a minimal repro? I've tried myself with a simple example but it's not giving me any errors: using TUnit.Assertions;
using TUnit.Assertions.Extensions;
namespace TUnit.TestProject;
public class Repro
{
[Test]
[MethodDataSource(nameof(MethodWithBaseReturn))]
public void DataSource_WithBaseReturn(BaseValue value)
{
}
public static IEnumerable<Func<BaseValue>> MethodWithBaseReturn() =>
[
() => new ConcreteValue(),
() => new ConcreteValue2()
];
public abstract class BaseValue;
public class ConcreteValue : BaseValue;
public class ConcreteValue2 : BaseValue;
} |
Beta Was this translation helpful? Give feedback.
-
Your error message says you're returning a |
Beta Was this translation helpful? Give feedback.
-
@thomhurst If you have a private place, I can give you the source code of the classes and the tests. |
Beta Was this translation helpful? Give feedback.
-
Sorry for this: I have multiple tests like that (one for each different data type) and forget to convert one of them to
If I change the |
Beta Was this translation helpful? Give feedback.
-
So the only problem that remains is the following error displayed in |
Beta Was this translation helpful? Give feedback.
-
It works perfectly with version 0.3.29. |
Beta Was this translation helpful? Give feedback.
Can you try v0.3.29?