unit-testing

How can I access private class members in Java?

I have data model classes that contain private fields which are meant to be read-only (via a getter function). These fields are set by my JPA persistence provider (eclipselink) during normal operation, using the contents of the database. For unit tests, I want to set them to fake values from a mockup of the persistence layer. How can I d...

Browserless, ant-task-oriented Javascript Unit Testing?

I'm looking for a javascript unit test framework that I can use as part of my automated maven build. This CANNOT use an actual browser, and it MUST be fully browserless. I've tried looking at a few posts on SO, but none seem to meet my needs. Is there such a javascript unit tester? I'm anxious to find out. ...

Mocking a useragent in javascript?

I'm looking for a way to programmatically change navigator.userAgent on the fly. In my failed attempt to get an automated javascript unit tester, I gave up and attempted to begin using fireunit. Immediately, I've slammed into one of the walls of using an actual browser for javascript testing. Specifically, I need to change navigator.use...

How to unit test a static method using a fake object for the dependency?

I've got my Fake object for HttpRequest ready (a wrapper and an interface)... since I don't need to call a constructor, how do I pass in the fake HttpRequest without breaking the interface of this method? public static int ParseQueryInt(string key, int defaultValue) { NameValueCollection nvc; if (HttpContext.Current.Request.Query...

Should we unit test web service?

Should we unit test web service or really be looking to unit test the code that the web service is invoking for us and leave the web service alone or at least until integration testing, etc.... ? EDIT: Further clarification / thought My thought is that testing the web service is really integration testing not unit testing?? I ask beca...

Xna: Mocking Texture2D

I'm writing WinForms / Xna app and I need some way to abstract away interaction with the GraphicsDevice in my Controller / Model code. I've created an interface IGraphicsService. I'll use that to abstract away things like loading textures. What I can't figure out though is what to do when I need to return some kind of Texture informatio...

Is it possible to Mock out time in a unit test?

Following on from this question...I'm trying to unit test the following scenario: I have a class that allows one to call a method to perform some action and if it fails wait a second and recall that method. Say I wanted to call a method DoSomething()...but in the event of an exception being thrown by DoSomething() I want to be able to...

How do I unit test a console input class?

In one of my applications I have a class which is responsible for user input. The default method of input is the console (keyboard), and I want to write some unit tests for it to make sure it is correct. I am considering using the google-test framework for my unit testing, which makes it easy to automate all the testing. However, I ...

How to unit test IDataErrorInfo?

Hi I am reading Asp.net MVC Framework and I am reading about IDataErrorInfo as form of validation. So I am just going to post what he has. Product Class using System; using System.Collections.Generic; using System.ComponentModel; namespace MvcApplication1.Models { public partial class Product : IDataErrorInfo { priv...

How do I test a method that needs to be called to set up the object before the test is run using Rhino mocks?

I'm having problems testing this scenario. An invoice has two states - finished and unfinished - and I want to test that the method Presenter.FinishInvoice() calls DAO.FinishInvoice() then calls DAO.GetInvoice() and then sets View.Invoice with the result. The problem is that I need to call DAO.GetInvoice() to get an invoice to finish...

how can we mock static , read only members , and functions that reside within the same class?

I'm using MOQ with tdd, i'm comfortable with the simple mock objects. Now moving on to the complex objects(i.e., objects containing other objects as properties ). i have problem creating mocks for three scenarios. when the method being tested wraps a static method. when the method being tested wraps a read only property. when the metho...

WCF Message.IsFault

I am trying to write a test and need to create a Message object with the IsFault property set to true. However, this property only has a getter. Does anyone know the best way to create a message where this property would be set to true? Thanks ...

C# String creation (specified length)

Is there a succinct way (i.e. not a for loop) to create a string of a specified length? Doesn't matter what is in the string. ...

Does anyone have a short document about unit tests for devs new to unit testing?

I've been tasked with writing a short document about unit testing. Basically guidance for devs who are required to write unit tests for the first time, and are somewhat unfamiliar with it. My first response was sure I can do that, but realized that there are whole books dedicated to the subject. I'm not quite sure how to distill the top...

Automated Unit testing - why? what? which?

I am a C# winforms developer with an experience of around a year. The only unit testing that I have been doing till now has been manual. I have thinking about following for sometime: Why do we need to have automated unit testing? How effective is it? If I want to start doing automated unit testing. Where should I start from? (have hea...

Code Design / Testability How To?

My team is designing a library that is wrapping calls to Active Directory to search and return a list of people. We have a person class that wraps up the information for a person found. We then use the List to wrap them up. When we call the search it uses the internal System.Directory library and returns a SearchResultCollection objec...

Unit Testing - What not to test..

I have gone through a number posts on stackoverflow and numerous articles about Unit Tests. I am just trying to figure out that what I have understood is right. Do not test anything that does not involve logic. For example: If there is a method in the service layer which simply invokes another method in the data access layer, don't tes...

How can I hide incompatible code from older Python versions?

I'm writing unit tests for a function that takes both an *args and a **kwargs argument. A reasonable use-case for this function is using keyword arguments after the *args argment, i.e. of the form def f(a, *b, **c): print a, b, c f(1, *(2, 3, 4), keyword=13) Now this only became legal in Python 2.6; in earlier versions the above ...

Forcing Unit Testing on Developers

First a little background. The company I work for writes web based software that is a hosted solution for our customers (ie ASP (Application Service Provider)). We are adopting agile practices such as Scrum and we execute sprints to build new features for our product. I am a proponent of TDD (Test Driven Design), and as a part of what...

How to organize unit testing of a library project in Xcode?

I'm not yet a fan of integrated development environments, but I'm trying to overcome my prejudices and learn Xcode. (Eclipse/CDT is next; I couldn't get that to work for me either when I tried last year, but that's a separate issue.) I am writing some new code in a new project that will become (part of) a small library. I want to unit...