Writing "unit testable" code?
What kind of practices do you use to make your code more unit testing friendly? ...
What kind of practices do you use to make your code more unit testing friendly? ...
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...
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 ...
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...
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...
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...
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. ...
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...
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...
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? ...
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...
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...
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 ...
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. ...
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(); ...
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....
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. ...
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...
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...
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...