<p>If I have code like this:</p>

<pre><code>        public XALServiceConfiguration CreateInstance()
        {
            var config = ConfigurationManager.GetSection(ConfigurationSectionName) as XALServiceConfiguration;
            if (config == null)
                throw new ConfigurationErrorsException("Configuration element 'xalService' was not found or is not of correct type.");
            return config;
        }
</code></pre>

<p>How can I test that the exception is thrown if the section is missing from the configuration file ? For other tests, the configuration section needs to be in the config file, so I cannot actually remove it from the file.</p>

<p>I am using the Visual Studio 2008 Unit test framework.</p>

You could just catch the exception in a
```
try catch
```
statment and do an
```
Assert
```
in the catch.