Tagged Questions
0
votes
1answer
108 views
Testing an MMO server [on hold]
I'm working on a server for a very large (feature wise) MMO. After some bad experiences with breaking changes that caused bugs weeks down the line, we'd like to add unit/automated/regression tests to ...
-1
votes
1answer
112 views
Approach to cover all the cases in Unit Tests [duplicate]
I am new to Unit Testing and i am able to write them but my problem is I am not sure that I have covered everything in Unit Tests. What could be the approach for testing some functionality in a code?
4
votes
3answers
172 views
How should I unit test a bitmap modifying method?
My Sprite class has a method:
private void updateWithBitmap(Bitmap b, int x, int y)
This will 'lay on top' the bitmap that's passed in, the top left corner of the passed in bitmap being at the x,y ...
2
votes
1answer
104 views
Separate Action from Assertion in Unit Tests
Setup
Many years ago I took to a style of unit testing that I have come to like a lot. In short, it uses a base class to separate out the Arrangement, Action and Assertion of the test into separate ...
2
votes
2answers
110 views
How to (or should I) have one assert per test with object comparisons? [duplicate]
I've recently read The Art of Unit Testing by Roy Osherove which I found very useful for helping me establish how to define a good unit test.
One key aspect of the guidelines Roy puts forward are to ...
1
vote
2answers
226 views
Testing C# Eventhandler Subscription
I want my unit tests to be able to verify that some events were subscribed or unsubscribed at specific points. Currently, I see two options.
VerifiableEventHandler
Each client subscribes using the ...
1
vote
2answers
470 views
Testing ASP.NET .aspx and .ascx code behind files
I am wondering how to test .aspx.cs and .ascx.cs code behind. Can I use unit testing and if so how? Are there alternatives that will help test the functions in the code behind files? I don't know how ...
1
vote
5answers
573 views
Unit Testing a method that contains two output type parameters
I was following a book Art of Unit Testing, This book says that You must not have any logic in Your asserts as this reduces readability of test, or I may be testing too many things at a time. Suppose ...
0
votes
2answers
97 views
Best practice to return a long string in a stub
I have some methods im trying to test which use a StreamReader dependency that i mock using Rhino mocks. But it is a large xmlFile. In the spirit of unit testing im trying to keep away from using a ...
1
vote
1answer
249 views
Unit testing methods with logical dependencies on other classes
Suppose I have an interface declaring the following method signature:
SearchResults SearchProducts(string type, string filter, string anotherFilter);
Inside a concrete implementation of this, I ...
1
vote
4answers
394 views
What are the valid test cases for method calls within if-else condition
I have a discount service that gets called if certain conditions are met. I need to write test cases to check if the discount service is called. My doubt is checking if the discount service is NOT ...
1
vote
2answers
162 views
TDD - Making assertions about C# Expression trees
How would you unit test the PerformUpdate method in the sample below? This is a (very) simplified version of some code that performs updates against a database where the schema is dynamic and ...
4
votes
1answer
353 views
Understanding unit testing concept
I've just started writing unit tests and I'm not sure am I doing it the "right way." Should I test every class "by removing dependencies"? In other words, does unit testing mean: "test part of a code ...
1
vote
1answer
112 views
Loading data for ShoppingCart item
I'm currently trying to cover our shopping cart with unit tests.
Class ShoppingCartItem has property Term. It also loads available terms for this item upon object creation. Currently this is done ...
0
votes
2answers
206 views
Unit test DAO code using SQL Lite when the application database is Oracle
We have an application with Oracle backend. The DAO layer is written in C# and uses nHibernet to perform the data operations.
To unit test our DAO code, we use SQL Lite which creates the database ...
0
votes
1answer
251 views
how to architect this to make it unit testable
I'm currently working on a project where I'm receiving an object via web service (WSDL).
The overall process is the following:
Receive object -> add/delete/update parts (or all) of it -> and return ...
19
votes
3answers
1k views
Difficulties With TDD & Refactoring (Or - Why Is This More Painful Than It Should Be?)
I wanted to teach myself to use the TDD approach and I had a project I had been wanting to work on for a while. It wasn't a large project so I thought it would be a good candidate for TDD. However, I ...
1
vote
1answer
1k views
Generic repository unit testing best practice?
How can I unit test my generic repository?
Unit testing code:
[TestClass]
public class UnitTestLanguage
{
private IUnityContainer _unityContainer;
private IUnitOfWork _uow;
private ...
1
vote
3answers
325 views
Does non-virtual-by-default lead us to composition-over-inheritance?
There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default ...
6
votes
2answers
471 views
Unit test SHA256 wrapper queries
I have the following SHA256 wrapper.
public static string SHA256(string plainText)
{
StringBuilder sb = new StringBuilder();
SHA256CryptoServiceProvider provider = new ...
2
votes
2answers
1k views
Need help understanding Mocks and Stubs
I'm new to use mocking frameworks and I have a few questions on the things that I am not clear on. I'm using Rhinomocks to generate mock objects in my unit tests. I understand that mocks can be ...
1
vote
4answers
1k views
Unit-Testing functions which have parameters of classes where source code is not accessible
Relating to this question, I have another question regarding unit testing functions in the utility classes:
Assume you have function signatures like this:
public function void ...
-3
votes
7answers
1k views
Unit Test OR Console Application [closed]
I am to write some one-off code in c#.net that will do some db manipulation of existing records and call a third party REST Api to update those records.
I proposed writing a unit test that does it. ...
1
vote
1answer
127 views
How do you distinguish your public API interfaces from the interfaces you use for testing/mocking?
Mocking frameworks are useful for creating mock objects that isolate the code under test from its surrounding software environment. Some mocking frameworks cannot mock non-virtual methods, so they ...
0
votes
2answers
166 views
Should I make a seperate unit test for a method, if it only modifies the parent state?
Should classes, that modify the state of the parent class, but not itself, be unit tested separately? And by separately, I mean putting the test in the corresponding unit test class, that tests that ...
57
votes
11answers
6k views
Is it a bad practice to modify code strictly for testing purposes
I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example).
My opinion is that it ...
2
votes
2answers
239 views
Should an integration test be used in place of a unit test involving personal data?
I am trying to develop a series of unit tests for a production system that are dependent on a person's social security number. While I am more than comfortable hard coding a clearly bad social ...
4
votes
5answers
672 views
How can I test parts of my application against the output of third party application?
I have a fairly new C# application, approximately 6 months old, that we are now trying to incorporate testing into. (Should have been done from the start but I can't change the past)
Parts of this ...
4
votes
2answers
307 views
Testcase runner for parametrized testcases
Let me explain my situation. I'm planning a kind of test case runner for doing testcases on external devices, which are microcontroller based. Lets consider the devices:
Device 1
Device 2
There ...
9
votes
4answers
795 views
In Unit Testing, why would I create a Repository twice?
The other day I was reading a little about Unit Testing and I saw some examples where people create a repository interface (i.e. IExampleRepository) and then create the real repository (public class ...
1
vote
1answer
725 views
How to write unit tests without mocking data
My design doesn't allow me to mock the data so I am using sqlite as test database that has minimum data to run the unit tests. Below is the pseudo code
//Method to be tested
public IList<Funds> ...
3
votes
5answers
3k views
Understanding unit tests/TDD for ASP.NET webforms [closed]
I'm the lead programmer at a small software firm (currently 4 developers including myself), we develop bespoke ASP.NET WebForms applications for businesses. I joined there in 2010 just after ...
13
votes
3answers
3k views
Is there any real value in unit testing a controller in ASP.NET MVC?
I hope this question gives some interesting answers because it's one that's bugged me for a while.
Is there any real value in unit testing a controller in ASP.NET MVC?
What I mean by that is, most ...
13
votes
3answers
906 views
Brittle unit tests due to need for excessive mocking
I've been struggling with an increasingly annoying problem regarding our unit tests that we are implementing in my team. We are attempting to add unit tests into legacy code that wasn't well designed ...
8
votes
1answer
729 views
Unit testing on visualization (3D graphics) frameworks
This is a follow up to this question. There I was asking how to do unit testing when you have a library of scientific algorithms. I have a similar problem now but with a different project.
I'm ...
11
votes
3answers
10k views
Best way to unit test methods that call other methods inside same class
I was recently discussing with some friends which of the following 2 methods is best to stub return results or calls to methods inside same class from methods inside same class.
This is a very ...
5
votes
1answer
315 views
Unit testing for a scientific computing library
I've had a bit of experience with unit testing before, in what I call (not pejoratively) the classic software engineering project: an MVC, with a user GUI, a database, business logic in the middle ...
5
votes
2answers
1k views
Event Driven Programming: A sequence of unfortunate events
I have a very basic game loop whose primary purpose is to check for updates & changes to a list.
I have contemplated using event driven programming to replace the game loop/list idea with an ...
6
votes
2answers
1k views
Helper static methods in TDD
I am creating an application which will be testable(unit + integration). In this application I have a FileHelper static class,
public static class FileHelper
{
public static void ...
25
votes
11answers
4k views
How do we make unit tests run fast?
We have reached the point in our project where we have almost a thousand tests and people have stopped bothering with running them before doing a check in because it takes so long. At best they run ...
8
votes
4answers
687 views
Is it useful to unit test methods where the only logic is guards?
Say I have a method like this:
public void OrderNewWidget(Widget widget)
{
if ((widget.PartNumber > 0) && (widget.PartAvailable))
{
...
7
votes
4answers
727 views
Unit testing and Test Driven Development questions
I'm working on an ASP.NET MVC website which performs relatively complex calculations as one of its functions.
This functionality was developed some time ago (before I started working on the ...
3
votes
3answers
1k views
Writing Unit Tests for a Class That Starts External EXE
I wrote a C# class that is used to start a list of EXEs (not one of mine - third party EXEs I have to run) and keep them running (will check occasionally to make sure it is still running, and start ...
4
votes
4answers
407 views
Do large test methods indicate a code smell?
I have a particular method called TranslateValues() (Cyclomatic-Complexity of 5) which I would like to test.
The test requires a substantial number of mock objects which take up most of the method; ...
4
votes
3answers
2k views
How to make Unit Tests to make sure stored procedure is deleting row from the database?
I'm new to unit testing and I need some help with the following.
I have created a small project to help me learn how to make Unit Tests. The functionality for one of the forms in my application ...
2
votes
2answers
1k views
Is this method of writing Unit Tests correct?
I have created a small C# project to help me learn how to write good unit tests. I know that one important rule of unit testing is to test the smallest 'unit' of code possible so that if it fails you ...
0
votes
2answers
1k views
Should I use a seperate class per test?
Taking the following simple method, how would you suggest I write a unit test for it (I am using MSTest however concepts are similar in other tools).
public void MyMethod(MyObject myObj, bool ...
4
votes
2answers
632 views
How and what should I be (unit) testing for in this method?
I am relatively new to unit testing and have a query about what/how I should be testing a certain method. For the following (psudo-c#) method I have created (not a real-life example) what would you ...
0
votes
1answer
2k views
Implementing a ILogger interface to log data
I have a need to write data to file in one of my classes.
Obviously I will pass an interface into my class to decouple it.
I was thinking this interface will be used for testing and also in other ...
1
vote
4answers
3k views
How to Console.WriteLine from [TestMethod]?
I am trying to show some information from a [TestMethod] method.
Usually we use NUnit and a line with Console.WriteLine runs fine and we can see it in 'output' window, but on this project we must to ...