All Questions
180 questions
1
vote
2
answers
137
views
How to test a dynamically list properly
I want to test that a bunch of buttons on screen are responding properly, this amount this increase dynamically thought the project and will be used in more than a single test.
My first try was using ...
1
vote
1
answer
154
views
NUnit Setup Method not using new values handed in
I'm trying to get better with TDD and implement some unit tests using NUnit for a desk booking application. My Setup is as follows...
[SetUp]
public void Setup()
{
deskBookingRequest = new ...
3
votes
3
answers
4k
views
NUnit Tests not running and have blue exclamation Icon next to them
Are you trying to tests out some methods, but when it comes down to it your tests arent even running?
Typically they might have a blue exclamation point next to them and when you run all tests the ...
2
votes
2
answers
624
views
MOQ Creating a Mock of an abstract class returns null
Firstly, I understand that the title of my question doesn't really suit the question; I just wasn't sure what the title should've been.
It is to the best of my knowledge that when creating a mock of ...
1
vote
1
answer
1k
views
Nunit test project cannot load System.Windows.Forms assembly to test a windows form based application targeting .Net 4.6.1
We have a Nunit test project targeting .Net Core 3.0 .
This test project writes tests against a windows form based project which has target framework of 4.6.1 and a class library project also ...
2
votes
3
answers
2k
views
c# unit test child method calls parameters
Here is my c# code.
I'm not sure how I should verify that Get method called with correct parameters.
public class ClassToTest
{
public IList<Products> GetProducts(string categoryId)
...
0
votes
1
answer
206
views
Test that a specific exception didn't happen in NUnit
First off, this is very similar to this question.
What I'm trying to do is run a test that passes if the program doesn't throw a specific exception, but if the program does that specific exception, I ...
0
votes
1
answer
1k
views
How to test this async delete method?
I´m trying without success to test a setup a repository Delete method:
[SetUp]
public void Setup()
{
var admin = new User
{
Id = ADMIN_USER_ID,
...
1
vote
1
answer
2k
views
NSubstitute Returns method and arrays
so I want to test roll results of dice set, but i can't pass an array as arg in Returns method like this:
[TestCase(new[]{2, 2, 3, 1, 5}, Category.Yahtzee, 0)]
public void ...
0
votes
2
answers
423
views
IEnumerable interface TDD using Mock in C# [duplicate]
Below is the FizzBuzz Generation Code,
public class BusinessHandler : IBusinessHandler
{
private readonly IEnumerable<IBusinessRule> BusinessRule;
public BusinessHandler(IEnumerable<...
0
votes
1
answer
2k
views
Unit Testing Remove one Item in my Mock Database
I am on learning unit testing and have a question.
I mocked my class ApplicationDbContext with my data.
Now I would like to delete an item from my data. :(
The first Test passed but the second ...
3
votes
3
answers
1k
views
How to execute every single test in a test class in an own process
We use C# and NUnit 3.6.1 in our project and we think of parallel test execution to reduce the duration. As far as I know, it is possible to parallel the execution of TestFixture with a Parallelizable-...
3
votes
1
answer
2k
views
test all combinations of parameters excluding one specific combination
I want to create tests that tests all combinations of parameters excluding one combination that will have a different expected result.
So far I have come up with
[TestCase(false, false, ...
0
votes
1
answer
138
views
NUnit Test For Setting Position C#
So I'm creating a Snake-game and want to test that the "Snake-food" changes Position when "eaten".
So I have a simple Position-class that looks kinda like this:
public class Position
{
...
2
votes
1
answer
2k
views
Moq Mock.Of<Obj> vs new Obj();
I'm doing lots of unit tests lately and I've discovered the Mock.Of<T> method from Moq library. After reading this and ultimately that I've found out that Mock.Of is great option for creating ...
3
votes
0
answers
190
views
TDD - Unit tests failing due to assumptions in the arrange phase [closed]
I'm doing (or trying to do) TDD to develop my business logic for an application.
I have a collection in one class that I expose as IReadOnlyList, because I want to make it clear that adding/removing ...
0
votes
1
answer
1k
views
Migration problems when migrate from NUnit 2.X to NUnit 3.X
I'm using NUnit 2.X library but want to use NUnit 3.X now. I have some problems about migration from 2.X to 3.X. First i have a setup fixture class. Here is the 2.X version;
using System;
using ...
1
vote
2
answers
2k
views
Writing unit test for methods which have network connection dependencies
I am writing a Downloader (for fun with TDD), in that i have a method, whose responsibility is to connect to the file.
class FileConnectorHttp : IFileConnector
{
public void ConnectToFile()
{
//...
2
votes
1
answer
7k
views
Nunit using an object in TestCaseSource or TestCase
I have just completed my first unit test class but was left feeling frustrated that I was copied and pasted so much of my logic. After some searching I found that [TestCaseSource] or [TestCase] was ...
3
votes
3
answers
552
views
Writing C# nunit test without having access to the rest of the code
I have a class Person and the interface:
interface IService
{
double GetAccDetails(int personId);
}
public class Person
{
private int _personId;
private IService _service;
public ...
0
votes
1
answer
989
views
Configuring Nunit with ASP.NET MVC Core 1.0
I wanted to configure NUnit for my ASP.NET Core 1.0 project. I have tried following : http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/
, but it's there for console applications.
...
1
vote
1
answer
2k
views
How to pass struct parameter to test function by using [TestCase] or [TestCaseSource] in NUNIT
I practice TDD nowadays.
I wanna simplify my poor test function by using [TestCase] or [TestCaseSource] attribute. please help me. this is my funcion now
[Test]
public void GetLength_TEST_1()...
0
votes
1
answer
55
views
Logic of calling a method to be tested in TDD
As I am new in tdd development, I tried mocking for the first time and I have
a doubt regarding the same.
Consider following example:
here goes Business
public class MyEmail
{
public bool ...
0
votes
2
answers
4k
views
Issue testing null check using NUnit
I am a junior dev that is new to unit testing. My company uses NUnit and I am trying to test a null check in a service method I created. Any idea what my Assert statement should look like if I am ...
0
votes
1
answer
425
views
Nunit TestCaseSource skips some cases
I'm wokring on C# program, VS2015, R#, Nunit. I have Nunit tests
[ Test ]
[ TestCaseSource( typeof( GeneralTestCases ), "TestStoresCredentials" ) ]
public void ...
2
votes
2
answers
133
views
Should I use a callback or introduce a public field to aid with unit testing?
I've seen adding public properties advocated in the Art of Unit Testing (by Roy Osherove) to help get at and setup awkward (or internal) collaborators/collaborations used by a SUT, and have used this ...
0
votes
0
answers
2k
views
NUnit tests not showing up in Visual Studio test explorer
I'm doing a simple little exercise but its kinda outside my current experience. I'm quite new to both visual studios and Nunits, basically I have created a simple database and a class to insert/delete/...
1
vote
0
answers
485
views
How to use NUnit TestCase with internal type as argument
I have got stuck while writing some tests when wanted to use TestCase attribute with some parameters.
I wanted to specify multiple test cases with some inputs and outputs but one of it is of type ...
1
vote
2
answers
1k
views
Moq with testing an array class
I need a proper way to test one of my classes,I am quite new to any mocking frameworks
I have the below Test class am using Nunit with Moq. I am getting confused as to how I should pass an array of ...
23
votes
1
answer
14k
views
Moq Async Callback Fails with multiple parameters
I'm trying to workout if it is something I am doing wrong, or its an issue in moq or NUnit. I am calling a soap endpoint and my service reference is generating both sync and async methods. The call I ...
4
votes
1
answer
164
views
Is it a good practice to include an expected result in a testcase?
Consider the following test:
[TestCase(2016, true)]
[TestCase(2017, false)]
[TestCase(2018, false)]
[TestCase(2019, false)]
[TestCase(2020, true)]
public void ...
0
votes
2
answers
447
views
TDD in Real Business Environment (C#, NO ASP.NET, SQL Server) [closed]
I want to keep myself as short as possible:
First: I read related posts, but they didn't help a lot.
See: What is a quality real world example of TDD in action?
Or: How do you do TDD in a non-...
4
votes
2
answers
922
views
How to keep Unit tests DRY and reducing Asserts
I am trying to implement a webserviceclass using the TDD approach, which sends out a bunch of webrequests and interprets the responses. I encapsulated the webrequests in several interfaces so that I ...
1
vote
1
answer
207
views
Testing many implementations of an interface (TDD)
What is the best practice when creating many implementations of an interface to ensure compliance with the interface's contract?
public interface IFoo {
/// <exception cref="System....
2
votes
1
answer
524
views
Correct way to to TDD on a file reading word builder
I'm trying to get a handle on TDD.
I'm creating a class which reads characters from a file, building words character by character.
The part I'm having a little trouble with is the method which builds ...
1
vote
1
answer
453
views
Fakeiteasy issue mocking soapclient
I'm trying to cover my business logic with unit tests using NUnit and fakeiteasy. But I suddenly stuck with faking calls to Soap client using fakeiteasy. I trying to do next thing
var ...
2
votes
2
answers
926
views
Test that I can iterate through dictionary and write keys and values to console
I'm trying to write a console application in C# (which I'm VERY new to) using TDD.
I'm trying to iterate through a dictionary containing strings as keys and integers as values, and output them to the ...
2
votes
1
answer
2k
views
NUnit TestCaseSource with parameters?
I have multiple test classes that implement an empty interface (ITest, expanded with IEnumerable).
Interface:
public interface ITest : IEnumerable
{
}
TestDataSource with a description:
[...
1
vote
2
answers
5k
views
Why can't I run Nunit tests from Visual Studio when colleague can?
My code has NUnit tests. My colleague is able to run the tests from within Visual Studio on their desktop, however I can't run them on mine. When I try to use Test Explorer and "Run All", it just ...
21
votes
2
answers
13k
views
Invalid signature for SetUp or TearDown method - What am I doing wrong?
I am trying to do some dependency injection for my tests using nUnit. I'm new to TDD and nUnit so it's possible I am missing something simple. So basically I've created a SetUp method for my ...
0
votes
2
answers
828
views
Calling non default constructor of tested class from test class
I'm new to unit testing and I'd like to know how is this, I guess typical, problem usually solved:
I have protected method that I'd like to test. I've overriden the tested class with the test class, ...
1
vote
1
answer
156
views
why test passes in vb? It should fail (it fails in the c# version)
I'm following examples in Professional.Test.Driven.Development.with.Csharp
I'm converting the code from C# into VB. (this example is the start of chapter 7)
Now having
Public Class ItemType
...
4
votes
3
answers
187
views
How can I isolate a data source such as DbSet?
I have a number of controllers that I am testing, each of which has a dependency on a repository. This is how I am supplying the mocked repository in the case of each test fixture:
[SetUp]
public ...
9
votes
4
answers
7k
views
Naming tests in TDD vs unit testing naming
I have been doing a number of tests for developing using TDD; i.e write my test first.
I have always been used to writing the test like so, using this naming convention.
...
4
votes
2
answers
1k
views
Should I assert the count or the result explicitly?
[Test]
public void SimpleFlatten()
{
// arrange
var sentences = new List<string> { "Hello World", "Goodbye World" };
// act
var result = sentences.SelectMany(n => n.Split(' ')...
35
votes
9
answers
102k
views
C# - Asserting two objects are equal in unit tests
Either using Nunit or Microsoft.VisualStudio.TestTools.UnitTesting. Right now my assertion fails.
[TestMethod]
public void GivenEmptyBoardExpectEmptyBoard()
{
var test = new Board(...
2
votes
2
answers
2k
views
How to check if a Tooltip is set on a Control
Let's say I've got the following code in a (part of a) method:
ToolTip tip = new ToolTip();
Control ctrl = new Control();
tip.SetToolTip(ctrl, String.Empty);
I want to assert in a test that in a ...
0
votes
1
answer
63
views
add pagination control for asp.net mvc
I am new to asp.net MVC. I am trying to understand how to add pagination for a list of items using MVC without code for a view. I am using nunit testing to check whether pager option is tested or not
0
votes
2
answers
962
views
TDD With MVC Repository pattern
I am in the process to design architecture for mvc based project. For better approach i want to use TDD (using NUnit framework) pattern. I have fallowing layers in project.
MVC Project
Application ...
0
votes
0
answers
140
views
Nunit TestCaseSource all must pass
Im using Nunit with sharpdevelop, ive made a testcasesource. It seems that as long as one passes, it goes green. I want the opposite, if even one fails, i want the test to fail. How can i accomplish ...