❔ xunit field scope

lets say i have a class for unit testing below:
class Tests
{
Dependency dep1;

public Tests()
{
dep1 = new Dependency();
}

[Fact]
public void test1()
{
Service s1 = new Service(dep1);
...
}

[Fact]
public void test2()
{
Service s2 = new Service(dep1);
...
}
}
class Tests
{
Dependency dep1;

public Tests()
{
dep1 = new Dependency();
}

[Fact]
public void test1()
{
Service s1 = new Service(dep1);
...
}

[Fact]
public void test2()
{
Service s2 = new Service(dep1);
...
}
}
will s1 and s2 have the same dep1 instance or will they get different ones? thanks
4 Replies
Mernayi
Mernayi2y ago
Same
cumslvt13
cumslvt132y ago
Also you could verify this just by logging GetHashCode method
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server