Showing posts with label tdd specflow. Show all posts
Showing posts with label tdd specflow. Show all posts

Tuesday, February 14, 2017

NUnit Exception: Error Loading Settings

This applies to NUnit 3.4.1.

I was doing some TDD one day, when Visual Studio crashed. After a few choice words, I booted things back up. Running the tests after starting back up threw up an error window I'd never seen before. It only showed when I used the R# test runner.


It wasn't very helpful, since half the message didn't seem to be showing. I was able to get the error message using the first trick from this article. That error message wasn't much help either.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
---------------------------
ReSharper Ultimate – System.ApplicationException: Error loading settings file
---------------------------
   at NUnit.Engine.Internal.SettingsStore.LoadSettings()

   at NUnit.Engine.Services.SettingsService.StartService()

   at NUnit.Engine.Services.ServiceManager.StartServices()

   at NUnit.Engine.TestEngine.Initialize()

   at NUnit.Engine.TestEngine.GetRunner(TestPackage package)

   at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.<>c__DisplayClass1.<RunTests>b__0()

   at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.WithExtensiveErrorHandling(IRemoteTaskServer server, Action action)
---------------------------
OK
---------------------------

Fortunately, this project happened to have a build script which also ran the unit tests. Running the build script returned the full error text. That error message showed me the real problem. It turns out the NUnit settings file was empty. That was causing the root element missing error.


Deleting the NUnit30Settings.xml file from the $AppData$\Local\NUnit directory cleared the problem.

Monday, August 29, 2011

SpecFlow Tests and Lists

Some days I just can't see the forest for the trees...

Sometimes you just want to pass a list to check against:

Scenario: some files match
	Given I have the following files
		| FileName           |
		| test.txt           |
		| sample.txt         |
		| sample.file.txt |
		| sample.file2.txt |
		And  I have the following processes
			| Regex        | Process         |
			| sample.*.txt | TestProcess.bat |
	When I run the application
	Then The files should be processed
		| FileName           |
		| sample.file.txt |
		| sample.file2.txt |

If you're using SpecFlow and need to pass in a list to one of your bindings, here's a simple one-liner to convert a table to a list of strings:

[TestClass]
[Given(@"I have the following files")]
public void GivenIHaveTheFollowingFiles(Table table)
{
    var files = table.Rows.Select(o => o["FileName"]);
}

'files' will be a list of the strings in the table. I'm sure there's a better way, but this one works.