c# - Getting info from currently running unit test -
i have find info running unittest helper class' static method. idea getting unique key each test.
i thought using testcontext
, not sure if possible.
exemple
[testclass] public void mytestclass { public testcontext testcontext { get; set; } [testmethod] public void mytestmethod() { testcontext.properties.add("mykey", guid.newguid()); //continue.... } } public static class foo { public static getsomething() { //get guid test context. //return base on key } }
we storing key on thread thread.setdata
, problematic if tested code spawn multiple thread. each thread need same key given unit test.
foo.getsomething()
not called unittest itself. code calling mock injected unity.
edit
i'll explain context little bit, because seems confusing.
the object created via unity entity framework's context. when running unit tests, context data in structure created foo.getsomething
. let's call datapersistance
.
datapersistance
cannot singleton, because unit tests impact each others.
we have 1 instance of datapersistance
per thread, witch nice long tested code single threaded.
i want 1 instance of datapersistance
per unit test. if unique guid per test, resolve instance test.
public static class foo { public static getsomething(guid guid) { //return base on key return new something(); } }
test:
[testclass] public void mytestclass { public testcontext testcontext { get; set; } [testmethod] public void mytestmethod() { guid guid = ...; something = foo.getsomething(guid); } }
Comments
Post a Comment