Now I can write one (large) test that walks through the entire primary flow. But that test could easily result in a method with 100+ lines. And I also want to test certain alternative flows, which would result in a method that could easily be 80% the same as...
To pass in variables use Data driven tests [DataSource(@"Provider=Microsoft.SqlServerCe.Client.4.0; Data Source=C:\Data\MathsData.sdf;", "Numbers")] [Test] static public void NUnitWriter() { int x = 0 int errorCode = Convert.ToInt32(TestContext.DataRow["ErrorCode"]); Assert.AreEqual (x, errorCode); } Passing in from Xml [DataSource("Table:CSharpDataDrivenTests.xml#FirstTable")] [Test] static public void NUnitWriter() { int x = 0 int errorCode = Convert.ToInt32(TestContext.DataRow["ErrorCode"]); Assert.AreEqual...
Found a solution to my problem Created a customised version of nunit-results that displays the indiviudal test names Thanks to Charlie Pool(https://launchpad.net/~charlie.poole) for making the source available
c#,unit-testing,visual-studio-2013,nunit
Break your test project to multiple projects that only reference a subset of the solution's projects. This is also good test housekeeping - have a separate unit test project for each solution project instead of one huge project with dependencies to anything else. There are several advantages to this: Tests...
You defined it as a value, but it must be a method: [<Test>] static member ConcatinationTest () = ... (converted a comment into an answer, as per OP's request)...
In F#, mutable values are assigned using <- rather than =. So your Setup method should look like: [<SetUp>] member public x.``run before test``() = state <- [] which works fine. For your second question, this layout works fine for me if you make the same change as above....
Solved it. Turns out you need to set the CallBase property on the System Under Test that you are mocking up. Test case is now: [Test] public void it_should_notify_developers_immediately_if_there_is_a_problem_when_checking_for_intraday_builds() { //Arrange var mockDua = new Mock<DUA>(); var mockIB = new Mock<IIntradayBuilds>(); mockDua.CallBase = true; // <<<< Added this line! //Act...
c#,visual-studio,unit-testing,nunit,test-explorer
This seems to be a bug in the NUnit core 2.6.4 version. I can reproduce it with 2.6.4, but using the 2.6.3 core - even with the 2.6.4 framework makes it work. So that is a workaround. All I needed to make it work or not was to change the...
debugging,visual-studio-2013,nunit,resharper
It appears that the ability to debug unit tests while other projects are running is a feature that was introduced in Resharper 9.x. The other developer was using a trial of it, it turns out. Now that he's reverted back to 8.2.2, he is seeing the same thing that I...
c#,nhibernate,nunit,nhibernate-configuration
I would suggest to use full path in the connection string: // instead of this <property name="connection.connection_string" >Data Source=MyFirstNHibernateProject.sdf</property> // we should use <property name="connection.connection_string" >Data Source=C:\MyFirstNHibernateProject\MyFirstNHibernateProject.sdf</property> Where the "C:\MyFirstNHibernateProject\" should be the full path to the "MyFirstNHibernateProject.sdf" Also, in case you are suing CE 4.0 I would suggest to...
Dependencies, gotta love dependencies, better yet static dependencies. If the underlying code in SerializeView is not that important for the unit test, then the easiest thing to do is to abstract out that method into another type and inject instead of inheriting it from a base class.... Something like this:...
c#,nunit,portable-class-library,visual-studio-2015,nunit-3.0
It is very likely that you should use xUnit.net for now, https://github.com/aspnet/Testing/issues/34 NUnit won't be ported unless someone steps in....
As has been discussed in the comments on your question, you can't really test your ImportsAndLoads method in isolation in its current form, using Moq. If you are using a high enough version of Visual Studio, then you may be able to test the method using Shims, however if you're...
You can do 2 separate asserts: Assert.AreEqual(person1.Name, person2.Name); Assert.AreEqual(person1.Name, person3.Name); Or you could create a helper function: public static class AssertEx { public static void AllAreEqual<T>(params T[] items) { for (int i = 1; i < items.Length; i++) { Assert.AreEqual(items[0], items[i]); } } } Which you could use like so:...
c#,osx,mono,nunit,xamarin-studio
I experienced the same problem and spent several hours in exporting variables etc. I still don't understand why the NUnit Console Runner has the conflict with .NET 4.5 when exporting the 4.5 mono framework. Solved the problem by calling the predefined nunit-console Command of the mono framework located in: /Library/Frameworks/Mono.framework/Commands/nunit-console4...
You are disposing the driver after every run but not instantiating before each run. So driver won't work as expected. Instantiate the driver inside LaunchBrowser() method and re-run the tests Just more info Dispose() resets the diver and, thus the instance is not valid anymore with the code block you...
visual-studio-2013,selenium-webdriver,nunit
The two main options for .NET development are, for the most part, NUnit, and MSTest. IMHO, neither are very well optimized for automated browser tests. You can force each to do what you want, but features such as TestNG's @DataProvider are a pain to implement, especially if you are dynamically...
unit-testing,visual-studio-2012,nunit
You should be able to group your tests by Traits, which includes the Category attribute. If you can't then you may need to update your Visual Studio to at least Update 1. A more detailed description, targeted at the MS framework is here but the TestAdapter seems to allow it...
nunit,pdb-files,opencover,shadow-copy
However, OpenCover is unable to track an assembly when the pdb file is absent. This is by design as instrumenting every assembly that is loaded without a PDB means instrumenting every IL operation rather than each sequence point, the information of which is in the PDB. Sometime later, pdb...
nunit,ncover,unit-testing,resharper-9.0
Looks like the latest update of 9.1 solved the problem. Thanks everybody.
You can call extension methods like normal static methods by passing an instance of the type being extended as first parameter (e.g. StringExtensions.Replace(str, dict)). If this extension method is located in your "main project", it should be tested in your main project's test suite, not in that of a project...
I needed multiple changes for solving the issue: Revised F# test code I needed to use TestFixture. module HelloWorld.Tests.Hello open HelloWorld.Core.Hello open NUnit.Framework //open FsUnit [<TestFixture>] type TestClass() = [<Test>] member tc.When2IsAddedTo2Expect4() = Assert.AreEqual(4, 2+2) [<Test>] member tc.shouldSayHello () = Assert.AreEqual("Hello", SayHello "World") Execute mono provided unit-console I had to...
asp.net-mvc,unit-testing,testing,nunit,nsubstitute
I don't know, how to pass Model value The short answer is that in its current form, you can't pass the model you've created in your test to your controller. This is a common problem that people run into when they first start trying to unit test their code....
c#,unit-testing,nunit,testcase,testcasesource
TestCase and TestCaseSource do two different things. You just need to remove the TestCase attribute. [TestCaseSource("_nunitIsWeird")] public void TheCountsAreCorrect(List<string> entries, int expectedCount) { Assert.AreEqual(expectedCount,Calculations.countThese(entries)); } The TestCase attribute is for supplying inline data, so NUnit is attempting to supply no parameters to the test, which is failing. Then it's processing...
Rep is a struct, so var rep = new Rep(); will store the rep data on the stack (the current stack frame being the constructor call). q = &rep; will get a pointer to rep, therefore q points to data on the stack. This is the real issue here, because...
Instead of Single, get the count and compare it against 1 like: list.Count(t => t.GetType() == typeof(foo)) ! = 1 ...
The usual solution for this would be to mock the MessageBox class and simulate what the Show method returns. Since it's a static method, it requires additional work and some modifications in your code. Here's a possible solution: Create a class that encapsulates the Show method: public class MyMessageBox {...
The newly added key for NUnit test reports can be found on the project c# settings page - under UNit Tests tab, and its value is: sonar.cs.nunit.reportsPaths Provided value should be the .xml output from the NUnit console runner....
c#,visual-studio,unit-testing,nunit
The Run Unit Tests, Debug Unit Tests are present due to an Extension that is Installed named Resharper, you can download this on a free 30 day trial. https://www.jetbrains.com/resharper/download/...
Not depending on another test doesn't mean you can't utilize other methods in the class that you are testing. So for testDelete() you could create a file and then delete it. For testCreateFailOnDuplicate() you could create a file and then try to create it again, validating that it threw an...
c#,unit-testing,nunit,async-await,mstest
It sounds like those test runners may be using reflection to check whether the method returning Task really is an async method. That doesn't mean the method would behave differently if they were run - but they're just not being run. It's like saying that: public string Name { get;...
It's possible you're using an older version of the console application; static test methods weren't supported until version 2.5. You can check the version by running > nunit-console.exe /? NUnit-Console version 2.6.4.14350 Copyright (C) 2002-2012 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright...
Indeed the problem comes from assembly resolution. You must tell the CLR where to find NDepend assemblies (i.e in the dir $NDependInstallPath$\Lib) You have 2 choices to do this. Suppose $NDependInstallPath$ is "C:\NDepend" just for example: Either edit AssemblyResolverHelper to resolve assemblies in "C:\NDepend\Lib" Either create a App.Config file for...
c#,nunit,resharper,integration-testing,entity-framework-6
I found the solution, that (after all) is pretty obvious. Below you can see the final solution. The key is the Database.SetInitializer that configure EF to initialize the database using the registered IDatabaseInitializers. EF6 allow you to use Context.Database.Initialize(true); that forces the database to run all the initializers. The boolean...
c#,unit-testing,nunit,fluent-interface
I can't see an obvious way to do this either. My first thought is that you need to resolve the expression up to a given point, which leave's your assertion looking like this: Assert.That(i, ((IResolveConstraint)Is.StringStarting("1").Or.StringStarting("2")) .Resolve().With.StringEnding("5")) Which is obviously a bit messy. You can add your own extension method to...
nhibernate,nunit,nhibernate-mapping,spring.net
To resolve the above issue, performed several steps, though I'm not sure specifically which one fixed it: Added reference to NHibernate.Validator, Version=1.3.1.4000 in my test project and NHibernate.Caches.SysCache, Version 3.1.0.4000 Added reference log4net, Version=1.2.10.0 to my test project to print out more diagnostic info Added references to System.Configuration, System.Web.ApplicationServices, and...
Yes, this option corresponds to the /domain=Multiple command line parameter. Note that ReSharper doesn't use the console runner. Instead it directly links the NUnit assemblies....
entity-framework,nunit,resharper
Try selecting "Use separate AppDomain for each assembly with tests" in ReSharper → Options → Unit Testing. This is an optimisation ReSharper makes that reuses AppDomains (they're expensive to set up), but has the side effect that only one app.config can be loaded, and it might be the wrong one.
c#,unit-testing,nunit,moq,internal
Add both [assembly: InternalsVisibleTo("InternalsVisible.DynamicProxyGenAssembly2")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] for nothing problem....
I wrote the blog post Hosting a Mock as a WCF service which you looked at to create MockServiceHostFactory. Two things: You don't need to call the line to exclude the ServiceContractAttribute from being copied to the mock object, this is handled for you by NSubstitute. There must be some...
Running an identical test twice should have the same result. An individual test can either pass or it can fail. If you have tests that work sometimes and fail another then it feels like the wrong thing is happening. Which is why NUnit doesn't support this out of the box....
Welp. After exploring Visual Studio's Assert implementation, Assert.Inconclusive() seems to do the trick!
It's likely that your issue is being caused by your test runner not supporting the TestCaseSource attribute, particularly if it is being reported as Create. NUnit renames tests that use TestCaseSource, to combine the argument names into the name of the test. For your test, it should be reported as...
DNX tests aren't currently supported by ReSharper. It's a whole new execution model, and hasn't yet been implemented for ReSharper. I'd expect to see support as DNX and asp.net stabilise and near release. Also, I don't believe nunit itself supports running as a DNX test runner - the xunit team...
I think you need to read up on reflection and what the Type type actually stands for. To get you started - if you want to get the types that have a specific attribute, check this script: open System open System.Reflection /// an attribute and some types to test it...
I'm not sure if there's any difference when you're running a selenium test, but with a normal nunit test you could do: if("nunit" == Process.GetCurrentProcess().ProcessName)) { ... } This gets your the name of the process that's actually executing the tests, rather than just checking if the process is currently...
So the results of my investigation are that when nunit discovers the tests it runs through the attributes and creates the objects, and nunit (2) discovers all the tests, even if you are only interested in running 1. Apparently this will change at some point for nunit 3. The complicated...
This is supported if you are using parametrised tests, you can specify the TestName when adding the TestCase attribute. If you aren't using TestCase, then you could use it as a less than ideal work around to achieve what you're trying to do. So you would declare your test like...
Currently, this support is not yet available. The package information for NUnit 3.0.0.0-alpha-4(Pre-release) mentions: This package includes the NUnit 3.0 framework assembly, which is referenced by your tests. You will need to install version 3.0 of the nunit-console program or a third-party runner that supports NUnit 3.0 in order to...
It seems that nunit CollectionAssert.AreEquivalent is exactly what you were looking for. This method compare between the collections. If a mismatch was found then the method will throw exception with the difference....
Unfortunately, you cannot pass variables to a test case unless they are constants.
nunit,automated-tests,fixtures,mbunit
Using NUnit I can get this working: [TestFixture("1", "2")] [TestFixture("a", "b")] public class Tests { private string _x; private string _y; public Tests(string x, string y) { _x = x; _y = y; } [SetUp] public void SetUp() { Console.WriteLine("Setup with {0}, {1}", _x, _y); } [Test] public void Test()...
I found a working solution to my problem. UIA fires a number of events. One of them indicates that a new window has opened. Subscribe a handler to the WindowOpenedEvent: Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Children, new AutomationEventHandler(NewWindowHandler)); public void NewWindowHandler(Object sender, AutomationEventArgs e) { AutomationElement element = (AutomationElement)sender; if (element.Current.Name == "PUT...
You should show in your code sample exactly what controller is and where it comes from, but looking at the XSockets link you provide I think I know what you are expecting. The problem you are having is a common one when testing with threads, sockets, or any scenario where...
First of all, releases of Visual Studio prior to VS 11 did not have the ability to directly run tests built with Open Source testing frameworks like NUnit. Basically, in order to run your NUnit tests, you can use the NUnit test runner GUI tool (look inside your NUnit install...
It's hard to say what might be causing your problem without seeing your [SetUp] code. I notice that your mocks and unit under test are member variables - maybe there is a problem with shared state with another test. I was able to write the same test, and have it...
f#,nunit,nullreferenceexception,fsunit
In the code, create is not a function but a value. It can be fixed by defining it as a function: let create() = … and calling it with parens: let strategy = Foo.SpecificFooStrategy.create() ...
You would need to override Equals and GetHashCode in Dollar. The defaults compare reference equality so your two different instances will not be the same. Your current equals method will not be used. A simple implementation: public override bool Equals(object obj) { Dollar dollar = (Dollar) obj; return amount ==...
c#,selenium,selenium-webdriver,nunit
It sounds like the site you're automating adds the elements representing the objects dynamically to the DOM, and that your code is then losing the race condition that you execute FindElements before the elements are actually added to the DOM. You'll need to implement some sort of wait in your...
c#,selenium,jenkins,nunit,automated-tests
As far as I currently know of, there is no solution to provide just that what you describe that you want. Best option is to use NUnit project files, modify settings there and pass the solution file to the runner. On the other hand, you could try to use the...
There is no equivalent annotation to [TestFixture] in JUnit. Classes with methods marked with @Test get run by most JUnit test runners without any other special markings; and @Before methods act like [SetUp]; and @After methods act like [TearDown].
We were able to find a solution to the issue. NUnit runner by default runs tests in a separate thread, meaning in the java bridge was being initialized on a thread that the tests were not running which caused the tests to not have access to the need .jar files...
I use for now Assert.Inconclusive(), executed="True", so it's the closest to what I wanted. If someone finds better, feel free to post....
c#,unit-testing,mocking,nunit,moq
If you want to mock the ExecutAsync method you can do it like this: Mock<IApiRequest> mock = new Mock<IApiRequest>(); mock.Setup(x => x.ExecuteAsync<UpcomingMovies>(It.IsAny<RestRequest>())) .Returns(Task.FromResult<UpcomingMovies>(/** whatever movies **/)); if you want to mock for a particlur request, replace It.IsAny<RestRequest>() with a reference to your request. To effectively test your class you need...
visual-studio,visual-studio-2012,selenium,selenium-webdriver,nunit
Yes you can run selenium test with NUnit console and just calling the respective dll. See this for command line options **EDIT: ** Download NUnit Runner here. Set the path of the executable to the system path. This will get you started with installation and, then create a basic batch...
c#,unit-testing,mocking,nunit,nsubstitute
I think your tests are mostly OK, but there are some bits I would question. Both of your tests have these lines at the bottom: signedRequest.Received(1).ConfigureSettings(Arg.Any<SignedRequestSettings>()); signedRequest.Received(1).Post(Arg.Any<String>()); Is it really important to those tests that these methods have been called on your signedRequest substitute? I'd suggest that it probably isn't....
c#,.net,unit-testing,nunit,moq
The point of mocking isn't to mock the central code you're testing, but to mock its dependencies. This works best when the dependencies are interfaces. Let's say you have this interface: public interface IFileLoader { string loadFileContents(string fileName); } and a class that implements it by actually opening and reading...
c#,.net,visual-studio,unit-testing,nunit
You must either install the NUnit VSAdapter vsix extension, or add the adapter as nuget package to your solution. The latest version is the 2.0, and the vsix is available here: https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d And the nuget package can be found here: http://www.nuget.org/packages/NUnitTestAdapter/ More information on these options can be found in...
When you have configured a "Version control path to custom assemblies" on your build controller and have an old NUnit.VisualStudio.TestAdapter.dll at that location, this dll will take precedence over the NUnit.VisualStudio.TestAdapter.dll in your project. I have removed this old dll to work with the NuGet package and the TestCategory filter...
unit-testing,tfs,nunit,tfsbuild,tfs2013
Found the reason - build agent folder in source settings of Build definition was not set correctly - instead of setting it somewhere under build agent working folder I set it outside of it that's why unit tests were not found.. I discovered this using Build process activity log (which...
c#,unit-testing,nunit,resharper
Actually there is no solution for quick-fix expected values. If your changes break a lot of integration tests, you have to manually correct all of tests. The only hint is to minimize distance between copy-paste operations of expected values....
exceptions were swallowed in the execute handler. They certainly should not have been. According to the source code, ICommand.Execute is (correctly) implemented as an async void method that awaits the asynchronous command. This means that the ICommand.Execute call is not swallowing the exception. However, it also cannot be caught...
No, the symbols you can define for C# projects can be defined in two places: In the project configuration In the .cs file itself The first will only impact the project for which it is set. Additionally, these symbols are used during compilation, and whole sections of code is simply...
The issue was that I did not have a ReferencePath in my <buildArgs> element. <buildArgs>/noconsolelogger /v:quiet ...snip... /p:ReferencePath="C:\Program Files (x86)\NUnit 2.6.4\bin\framework" </buildArgs> Big thanks to Matteo for this blog post https://ilmatte.wordpress.com/category/cruisecontrolnet/...
c#,visual-studio-2013,f#,nunit,nuget
My question is stupid. .fs files cannot be added to C# project like for example .vb files. To do this properly one needs to add F# project to solution, see screenshot below. Implementation: module Implementation let Concat(text:string) = "root"+ text Test: module Test open NUnit.Framework [<TestFixture>] type Test() = member...
You can turn DivideCases into a method: private object[] DivideCases() { var amountOfSamples = qtyCmd(); var result = new object[amountOfSamples]; for (var i = 0; i < amountOfSamples; i++) { result[i] = new object[] {getCmd[i]}; } return result; } And then use it with TestCaseSource: [Test, TestCaseSource("DivideCases")] public void TestMethod(object[]...
c#,nunit,inversion-of-control,castle-windsor,nlog
Adding the following to the .nunit project file fixes this issue: configfile="Hl7ic.Engine.Test.dll.config" Even though the above runtime config setting was properly set in the test.dll.config, the nunit project didn't know to use the test.dll.config file. I always thought it was implicitly known to nunit, but apparently it needs to be...
c#,windows,unit-testing,mono,nunit
It looks like the Uri class has changed in Mono 3.12 so NUnit 2.4.8 is not returning the correct path to the NUnit assembly. Mono 3.3 on Windows works without any errors. I have opened a bug on bugzilla for this problem. It seems to be possible to use NUnit...
use the plain implementation. I won't recommend you to use fake in this case. the effort to create fake will cost more then just create tree for each scenario you will test. another danger is to create over-specified test which will failed on any change. your method will probably implement...
There is only one way to get an assertion failure message or an exception message... the solution is to implement an extension class! About this topic I suggest you to visit these links: http://schlapsi.com/2007/05/build-nunit-addin/; Additional log output on NUnit test fail; http://jimmykeen.net/2015/02/28/logging-test-results-with-nunit/ Here my code that implements the most important...
It looks like you are using Resharper, to change the noshadow setting you open the Resharper -> Options... menu and go to the Tools -> Unit Testing panel. There is a "no shadow" option to Control the shadow copying behaviour: ...
tfs,msbuild,nunit,build-process,tfsbuild
Found the issue, the build controller had an older version of NUnit Core dlls (0.9) so updated them and SpecFlow started to work with the teardown. Also, the VS NUnit Test ADaptor dlls had to be alongside those core dlls....
It looked like NUnit was tryging to automatically add bin\Debug to the bin path. The way I solved it is to specify explicitly what kind of bin path to use. Here is the .nunit project file: <NUnitProject> <Settings activeconfig="Debug" /> <Config name="Debug" binpathtype="Manual"> <assembly path="bin/Debug/MyUnitTests1.dll" /> <assembly path="bin/Debug/MyUnitTests2.dll" /> </Config>...
c#,multithreading,unit-testing,nunit
I figured it out! I had made a change which resulted in a whole lot of tests stuck waiting forever for something which never happened. This manifested itself in some tests as hanging forever, and in the remainder as raising the aforementioned InvalidOperationException. So, in brief, when a lot of...
c#,unit-testing,delegates,nunit,nsubstitute
I second Sunny Milenov's answer, but would go one step further by advising you to change your design. I have learned the hard way that many of these headaches with testing base class behavior go away when you follow the principle of composition over inheritance. I.e., if you refactor your...
c#,entity-framework,unit-testing,nunit,rhino-mocks
Few things that should be done better: mock instance can be created via static MockRepository.GenerateMock method (repository instance you are using is old API) DepartmentRepository property should be mocked as Insert call verification will be made mocks.ReplayAll() is not needed call to depService.GetAll() is not needed - in your test...
c#,unit-testing,mocking,nunit,nsubstitute
NSubstitute like most mocking frameworks can only intercept calls to virtual methods. It is able to stop the call to Broadcast, because it is virtual. You need to make EmitTo virtual if you want to stop it being called. It needs to be: public virtual void EmitTo(string connectionId, ChatMessage message)...
c#,visual-studio-2013,nunit,testcase
You have a [TestCase] attribute on yours that isn't on the sample. The sample attributes: [Test, TestCaseSource("DivideCases")] Yours: [TestCase] [TestCaseSource("DivideCases")] ...
Weird enough, it seems that the NUnitTestAdapter package is not compatible with Autofixture AutoData attribute... I installed TestDriven.Net and ran the tests with it and AutoData works perfectly, feeding the parameters to the method with no problem. Thanks for all your answers!...
c#,parallel-processing,nunit,specflow
Thanks a lot for the suggestions. I come out with own custom solution - just exploring the test dll with reflection from a custom command line app which then spawns separate OS processes each of them calling nunit-console.exe with the --include parameter specifying only a particular group of tests. This...
You need to use NUnit 2.6.3 for the current release of Concordion.NET. Unfortunatelly, NUnit addins are version dependent (http://nunit.org/index.php?p=extensionTips&r=2.6.4). This is also stated in the documentation of NUnit: "Most of the add-in samples provided with NUnit are currently version dependent." NUnit 2.6.4 was released on December 16th, 2014. Future releases...
c#,selenium,webdriver,nunit,compatibility-mode
This is better description of my issue: I need to test a site that I can't edit. The site works only in compatibility mode in my IE 11 (it is made for ie 7 doc type 5). I want to run tests and cookies should be cleaned before that. But...