Are TestContext.Properties read only ?
Posted
by DBJDBJ
on Stack Overflow
See other posts from Stack Overflow
or by DBJDBJ
Published on 2010-03-25T16:36:43Z
Indexed on
2010/03/26
8:13 UTC
Read the original article
Hit count: 304
Using Visual Studio generate Test Unit class. Then comment out class initialization method. Inside it add your property, using the testContext argument.
//Use ClassInitialize to run code before running the first test in the class
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
/*
* Any user defined testContext.Properties
* added here will be erased upon this method exit
*/
testContext.Properties.Add("key", 1 ) ;
// above works but is lost
}
After leaving MyClassInitialize, properties defined by user are lost. Only the 10 "official" ones are left.
This effectively means TestContext.Properties is read only, for users. Which is not clearly documented in MSDN.
Please discuss.
--DBJ
© Stack Overflow or respective owner