{"action":"created","issue":{"url":"https://api.github.com/repos/nunit/docs/issues/54","repository_url":"https://api.github.com/repos/nunit/docs","labels_url":"https://api.github.com/repos/nunit/docs/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/nunit/docs/issues/54/comments","events_url":"https://api.github.com/repos/nunit/docs/issues/54/events","html_url":"https://github.com/nunit/docs/issues/54","id":150197669,"number":54,"title":"OneTimeSetUp runs after code to generate TestCases","user":{"login":"doubleyewdee","id":3023323,"avatar_url":"https://avatars.githubusercontent.com/u/3023323?v=3","gravatar_id":"","url":"https://api.github.com/users/doubleyewdee","html_url":"https://github.com/doubleyewdee","followers_url":"https://api.github.com/users/doubleyewdee/followers","following_url":"https://api.github.com/users/doubleyewdee/following{/other_user}","gists_url":"https://api.github.com/users/doubleyewdee/gists{/gist_id}","starred_url":"https://api.github.com/users/doubleyewdee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doubleyewdee/subscriptions","organizations_url":"https://api.github.com/users/doubleyewdee/orgs","repos_url":"https://api.github.com/users/doubleyewdee/repos","events_url":"https://api.github.com/users/doubleyewdee/events{/privacy}","received_events_url":"https://api.github.com/users/doubleyewdee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-21T21:39:43Z","updated_at":"2016-04-21T22:33:57Z","closed_at":"2016-04-21T22:33:57Z","body":"Simple-ish example below. Basically setup for the fixture should probably run before test case values are generated. The below example throws a NullReferenceException before any tests are run which is not at all expected.\r\n\r\n[TestFixture]\r\npublic class MyTests\r\n{\r\n    private static string SomeValue = null;\r\n    private static IEnumerable<string> Values\r\n    {\r\n        get\r\n        {\r\n            yield return SomeValue.Substring(1) + \"foo\";\r\n            yield return SomeValue.Substring(1) + \"bar\";\r\n        }\r\n    }\r\n\r\n    [OneTimeSetUp]\r\n    public void OneTimeSetUp()\r\n    {\r\n        SomeValue = \"some value\";\r\n    }\r\n\r\n    [Test, TestCaseSource(nameof(Values))]\r\n    public void SomeTest(string value)\r\n    {\r\n        Assert.IsNotNull(value);\r\n    }\r\n}\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nunit/docs/issues/comments/213144243","html_url":"https://github.com/nunit/docs/issues/54#issuecomment-213144243","issue_url":"https://api.github.com/repos/nunit/docs/issues/54","id":213144243,"user":{"login":"CharliePoole","id":2678661,"avatar_url":"https://avatars.githubusercontent.com/u/2678661?v=3","gravatar_id":"","url":"https://api.github.com/users/CharliePoole","html_url":"https://github.com/CharliePoole","followers_url":"https://api.github.com/users/CharliePoole/followers","following_url":"https://api.github.com/users/CharliePoole/following{/other_user}","gists_url":"https://api.github.com/users/CharliePoole/gists{/gist_id}","starred_url":"https://api.github.com/users/CharliePoole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CharliePoole/subscriptions","organizations_url":"https://api.github.com/users/CharliePoole/orgs","repos_url":"https://api.github.com/users/CharliePoole/repos","events_url":"https://api.github.com/users/CharliePoole/events{/privacy}","received_events_url":"https://api.github.com/users/CharliePoole/received_events","type":"User","site_admin":false},"created_at":"2016-04-21T22:33:57Z","updated_at":"2016-04-21T22:33:57Z","body":"This is the documentation repository. You should file issues here if you see a problem with the documentation. This sounds more like a feature you want in NUnit itself. For that see https://github.com/nunit/nunit\r\n\r\nIn any case, what you describe here is well known and is how NUnit works. Tests are loaded (discovered, created) before being run. OneTimeSetUp is one of the first steps in __running__ the test, but it still takes place eons after the test is created. That's why you can't use things set in one time setup to create the tests.\r\n\r\nYou can think of it this way... until there is a test, it can't be run. Run depends on load. We can't have load depend on run as well or things would be circular. You might also think of a gui: what you see displayed in a gui __before running the tests__ is all the stuff that is defined at load time.\r\n\r\nThere is a feature, planned for some future release, called dynamic tests, which would not be loaded in advance but created on the fly at run time. You'll find that if you search the above repository. Sorry to say, there's no schedule for when we will do it, but it's on our horizon."}}