unit-testing

Writing "unit testable" code?

What kind of practices do you use to make your code more unit testing friendly? ...

How to break dependencies without modifying production code?

From my initial readings on unit testing (I'm a beginner) it is wise to put all of your setups and tests in a separate project from the code being tested. This seems ideal to me, as well. However, I've recently begun reading The Art of Unit Testing, trying to discover how to break dependencies on things such as database calls. The met...

How can I make a generic unit test for all my classes that inherit from a base class?

I am creating a base class (or base entity) since all my database tables will have a companyID field. In my unit tests, I have to make sure the companyID value is correct. If I am returning a list of objects, all the companyIDs should be the same. Is there a generic way of me writing a test that will loop through all the values, that ...

Android Eclipse Plugin: Instrumentation Test Runner not specified.

I'm getting this error when trying to run unit tests from Eclipse with an Android Project. The list of Instrumentation Test Runners is empty in the Android preferences. [2009-06-17 23:57:51 - MyApp] ERROR: Application does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library an...

How to set the ErrorCode of a ManagementException?

I want to handle a ManagementException exception for a specific ErrorCode only and am having trouble writing the unit test for it. Ordinarily, I would write the test so that it is something like the following: Searcher search = MockRepository.GenerateMock<Searcher>(); // wrapper for ManagementObjectSearcher ... search.Expect(s => s.G...

Taking unit testing to the next level

Over the past year or so I have been developing my TDD chops so that I am now fairly good at the essentials - writing tests first, mocking frameworks, testing as small things as possible, DI etc. However I feel like there are still a lot of things that I am not getting out of unit testing. For example, I often find that unit testing in...

How to test an ajax submition in ASP.NET MVC?

Specifically, how can I pass the static method Request.IsAjaxRequest()? I get the exception 'System.ArgumentNullException' when I try to test the following code: if (Request.IsAjaxRequest()) { return Json(data); } return View(data2); I'm using Moq. Thanks for any help. ...

File reading and testable code

I have a piece of java code which reads strings from a file and creates a map out of the strings. As this code depends on a file, unit testing is clumsy. How does one design such pieces so that code can be unit tested? One approach that I can think of is, instead of this piece taking a file as an argument it can take an input stream. I...

Access Django testserver from Django test

Hi! I want to write a unit test that performs HTTP requests directly (instead of using django.test.client.Client). If you're curious why - it's because I want to test a Thrift-over-HTTP API that I expose from my Django application - and I want to use the Thrift client in the unit test. The problem is that during tests, the server is n...

How do you speed up java unit tests?

Currently our project has over 3000 unit tests, and "ant testAll" takes well over 20 minutes. besides getting better hardware, are there ways to speed things up? ...

Teach emacs recognize Boost.Test errors

This is an output of Boost.Test when test case failes: bjam toolset=msvc ...patience... ...found 1287 targets... ...updating 4 targets... compile-c-c++ ..\bin\test\Function.test\msvc-8.0\debug\link-static\threading-multi\Function.obj Function.cpp msvc.link ..\bin\test\Function.test\msvc-8.0\debug\link-static\threading-multi\Function.ex...

How to use TypeMock Isolator with Linq to SQL and DataContext

Hi, i am using TypeMock Isolator to fake the tables on my DataContext like this: Isolate.Swap.CallsOn(ctx.GetTable<TTable>()).WithCallsTo(content); I now can fill the "database" with arbitrary data on each test. In order to get meaningful data for the test scenario into the DataContext i usually have to create 3-5 objects. Now, the p...

How can I debug a NUnit unit test using resharper?

I am running VS2008 with Resharper 4.1, NUnit 2.2.7, coding in c#. I would like to use an NUnit unit test as a debugging harness while I am developing the code. My test is in a different project than the method being tested, but in the same solution. I have put breakpoints into the unit test as well as the method being tested. VS is ...

Cannot find the Test Project in VS2008

I could not find the Test Project in the VS2008. Can anyone point me out what components I need to install? PS: I cannot afford the Resharper. ...

How to test if a button click opens a new Form with NUnitForms?

Hi, I'm new to C# and trying to write a simple GUI Unit Test with NUnit and NUnitForms. I want to test if a click on a button opens a new Form. My application has two forms, the main form (Form1) with a button that opens a new form (Password): private void button2_Click(object sender, EventArgs e) { Password pw = new Password(); ...

Using groovy to mock wrapped class

I am currently trying to go back through and write unit tests for some code that wraps an existing class. The function I am looking for has code that looks like the following... private OldObject oldObject ... public Boolean method(){ Boolean returnValue = false if(oldObject.method(100)){ returnValue = true } if(oldObject....

How to trace "out of memory" error from XCode based unit-test

I am using XCode 3.0 with iPhone SDK and have a small iPhone application that includes a unit test for sqlite, however I get "out of memory" when I run it. How do I trace root cause of the error? Thanks. ...

Tips for testing data intensive legacy application

I'm working on a very large, data-intensive legacy application. Both the code base & database are massive in scale. A great deal of the business logic is spread across all of the tiers including in stored procedures. Does anybody have any suggestions on how to begin applying "unit" tests (technically integration tests because they n...

Continuous unit testing with Pydev (Python and Eclipse)

Is there a way to integrate background unit tests with the Pydev Eclipse environment? My unit tests run well, but I would like to integrate them to run in the background based on source file changes (e.g. with nose) and to integrate the result back to Eclipse (I'm thinking big red X when tests fail with a console and trace log view). N...

How to unit test business rules?

I need a unit test to make sure I am accumulating vacation hours properly. But vacation hours accumulate according to a business rule, if the rule changes, then the unit test breaks. Is this acceptable? Should I expose the rule through a method and then call that method from both my code and my test to ensure that the unit test isn't so...