Repository navigation
Replies: 2 comments
|
Hi, yes, this is expected behaviour. You've diagnosed it correctly. Why it happens TUnit builds every test before it starts running anything. Building a test means resolving its data sources, so the constructor for
The tests never overlap. The constructor simply runs much earlier than the test itself. Also note that with the default Recommended workaround: Move the work that touches the cache out of the constructor and into public class Type2 : IAsyncInitializer
{
public Type2()
{
// keep the constructor free of side effects on shared state
}
public Task InitializeAsync()
{
// register in / read from the cache here
return Task.CompletedTask;
}
}Use I reproduced your scenario. With the registration in the constructor, the cached-instance test failed on every run. With the registration in Alternatives
The lifecycle docs list |
|
Thanks for your answer. I respond a little late sorry. One solution would indeed have been to use specialized and cloned fixtures classes of my 'real' tested ones where I'd have transfer set/reset inner states (properties / fields) mechanism out of constructor into an But as I already use a Factory Pattern in my 'real' project under test, I instead used to get rid of most of my I briefly look for built in initialization mechanisms in .Net, something like you have in TUnit via your I still don't know if [performance / resources utilization / overhead /architecture maintainability] wise it is (that?) worst using my solution over |
Uh oh!
There was an error while loading. Please reload this page.
Hi, I stumble on a issue that I can summarize this way :
What I found it can happen is that :
cachedInstanceis constructed from ClassDataSource TUnit mechanism. The project under test have it cached in its cacheTest1()is running first, meaningcachedInstanceis cleaned from cache asTest1()call a cleaning cache method (CleanCache()).Test2()is running with acachedInstancethat is not cached anymore.So I suppose it is due to the fact all data sources arguments are constructed first for the discovered tests, and then the running tests orchestration is running (concurrently excepted for those with [NotInParallel] attribute). So whereas I expected the 2 tests to run in complete isolation from each other, the data sourced argument construction could end up being interleaved between their execution.
Is that the expected behavior ? If so is there a recommanded workaround ?
All reactions