unit-testing

Is Assert.Fail() considered bad practice?

I use Assert.Fail a lot when doing TDD. I'm usually working on one test at a time but when I get ideas for things I want to implement later I quickly write an empty test where the name of the test method indicates what I want to implement as sort of a todo-list. To make sure I don't forget I put an Assert.Fail() in the body. When trying...

Unit testing a JAX-RS Web Service?

I'm currently looking for ways to create automated tests for a JAX-RS (Java API for RESTful Web Services) based web service. I basically need a way to send it certain inputs and verify that I get the expected responses. I'd prefer to do this via JUnit, but I'm not sure how that can be achieved. What approach do you use to test your we...

Testing for Random Value - Thoughts on this Approach?

OK, I have been working on a random image selector and queue system (so you don't see the same images too often). All was going swimmingly (as far as my crappy code does) until I got to the random bit. I wanted to test it, but how do you test for it? There is no Debug.Assert(i.IsRandom) (sadly) :D So, I got my brain on it after waterin...

VSTS Code Coverage bug?

Has anyone experienced this VSTS Code Coverage "bug?" Do you have any suggestions? I am doing code coverage analysis with Visual Studio, which is generally an easy task now with the tools that are included. However, I have an issue that I can't overcome. Let's say I have assemblies A, B, C, and D and have marked them all for coverage a...

Best Practices of Test Driven Development Using C# and RhinoMocks

In order to help my team write testable code, I came up with this simple list of best practices for making our C# code base more testable. (Some of the points refer to limitations of Rhino Mocks, a mocking framework for C#, but the rules may apply more generally as well.) Does anyone have any best practices that they follow? To maximiz...

Is there any way to use XmlSiteMapProvider within WinForm/Console/VSTest application?

I wonder whether there is a workaround for using the standard XmlSiteMapProvider within a non asp.net application, like WinForm/Console or, in my case, VS Unit Test one. The following code fails, because it cannot create a path to the .sitemap file inside a private GetConfigDocument method. XmlSiteMapProvider provider = new XmlSiteMapP...

Free/Open Source Test Generator for Java?

Are there any libraries for Java that can generate unit tests or unit test skeletons for existing code? I'm looking for something similar to pythoscope. Ideally it would generate code that follows JUnit4 or TestNG conventions. It looks like Agitar does something like this, but I'm looking for something free. ...

Unit Testing data?

Our software manages a lot of data feeds from various sources: real time replicated databases, files FTPed automatically, scheduled running of database stored procedures to cache snapshots of data from linked servers and numerous other methods of acquiring data. We need to verify and validate this data: has an import even happened i...

Favorite .NET Unit Testing framework

I've been using NUnit for a few years. I've tried MBUnit for a short while as well as Zenebug and XUnit but I keep coming back to NUnit. What is your favorite/most used Unit test Framework? Can you explain why you're using it? ...

How can I write a unit test for a controller class that uses winforms for views?

Has anyone been able to successfully unit test methods that are, by necessity, coupled to the System.Windows.Forms.Form class? I've recently been working on a C# winforms application, trying to build it with an MVC structure. This is difficult enough, given that the framework isn't really built with this in mind. However, it gets even...

Unconditionally execute a task in ant?

I'm trying to define a task that emits (using echo) a message when a target completes execution, regardless of whether that target was successful or not. Specifically, the target executes a task to run some unit tests, and I want to emit a message indicating where the results are available: <target name="mytarget"> <testng outputDir...

What is the best framework for Unit Testing in JavaME?

What is currently the best tool for JavaME unit testing? I´ve never really used unit testing before (shame on me!), so learning curve is important. I would appreciate some pros and cons with your answer. :) ...

Unit testing code with a file system dependency

I am writing a component that, given a ZIP file, needs to: Unzip the file. Find a specific dll among the unzipped files. Load that dll through reflection and invoke a method on it. I'd like to unit test this component. I'm tempted to write code that deals directly with the file system: void DoIt() { Zip.Unzip(theZipFile, "C:\\fo...

How do you test that a Python function throws an exception?

How does one write a test that fails only if a function doesn't throw an expected exception? ...

Is duplicated code more tolerable in unit tests?

I ruined several unit tests some time ago when I went through and refactored them to make them more DRY--the intent of each test was no longer clear. It seems there is a trade-off between tests' readability and maintainability. If I leave duplicated code in unit tests, they're more readable, but then if I change the SUT, I'll have to t...

Lots of the tests in the test suite are failing! Any advice on debugging it?

I already solved this but thought I'd ask anyway... I have a large application with a reasonably comprehensive test suite and unit test system. I was working on it and made a change that shouldn't have broken anything and suddenly dozens of test are failing. What should I do? I'm looking for a list of things that help isolate bugs. Tip...

How to unit test immutable class constructors?

I have an immutable class with some private fields that are set during the constructor execution. I want to unit test this constructor but I'm not sure the "best practice" in this case. Simple Example This class is defined in Assembly1: public class Class2Test { private readonly string _StringProperty; public Class2Test() ...

How do you create tests for "make check" with GNU autotools

I'm using GNU autotools for the build system on a particular project. I want to start writing automated tests for verifcation. I would like to just type "make check" to have it automatically run these. My project is in C++, although I am still curious about writing automated tests for other languages as well. Is this compatible with pre...

Mocking classes that aren't interfaces

I've been writing some providers in c# that inherit from the providerbase class. I've found that it's hard to write tests that use the providers as most mocking frameworks will only allow you to mock an interface. Is there any way to mock a call to a provider that inherits from providerbase? If not, is there a pattern that I can use t...

How to (with SimpleTest) write an AssertTags test with regex?

I wish to test a function that will generate lorem ipsum text, but it does so within html tags. So I cant know in advance the textual content, but i know the html structure. That is what I want to test. And maybe that the length of the texts are within certain limits. So what I am wondering is if the assertTags can do this in a way parap...