unit-testing

How can I test that a SQL "CREATE TABLE" statement is equivalent to an existing table?

For each table in my MySQL database I have a mytablename.sql file which contains the CREATE TABLE statement for that table. I want to add a test to check that noone has added/altered a column in the live database without updating this file - that it, I want to check that I can re-create an empty database using these scripts. How can I ...

How could the stack trace for my unit test not match the actual source?

In a C# class library, and set of tests. Everything was going well until I added a new set of tests - they run correctly on my machine, but fail on the TFS Build server. The stack trace in the build log makes no sense - the constructor of one class appears to be mapped to one of it's methods. If my class looks a little like this: 1. p...

Android - poster child project

In my past programming experience I found that learning by example is the shortest way to improve my skills. I'm now looking for a "poster child" opensource Android project which would follow best practices such as having good unit-test coverage, following clear design patterns, have well written, well documented sources and (hopefully) ...

Cleaning ReSharper's TestResults files?

I'm using ReSharper 4.5 to execute my MSTest unit tests in VS2008. With each test run, it's creating files in this path: testProjectFolder\bin\Debug\TestResults How can I clean/delete those files from within Visual Studio? If I can't delete them from within Visual Studio, when can I expect them to be removed? EDIT: I see Visual Stu...

To test or not to test - keyboard hook functionality.

Hello! I've never used TDD and unit testing "properly", but would like to learn some techniques. Could you please help me with the idea on writing test methods for this not-so-testable (in my opinion) case. The class I want to test is yet to be written (I remember, I need to write the test first), but it will have a method to hook on W...

Given a short (2-week) sprint, is it ever acceptable to forgo TDD to "get things done"?

Given a short sprint, is it ever acceptable to forgo TDD to "get things done" within the sprint. For example a given piece of work might need say 1/3 of the sprint to design the object model around an existing implementation. Under this scenario you might well end up with implemented code, say half way through the sprint, without any te...

BDD/TDD mocking data the tricky way.

So a coworker and I are in a fairly heated debate. We are beginning a new project and we are attempting to use BDD. We are both first-timers and don't fully understand what practices should be used. We've written some specs and we are now implementing the code. Things are getting pretty tricky since there is a lot of database interaction...

Rhino Mock stub returns different type from expected and breaks my unit test

Related to yesterday's question. I implemented the solution proposed by Mehrdad Afshari but this caused another problem. To recap: I have a class containing a dictionary of Type->IList<Type> e.g. Cat->{cat1, cat2}, Zebra->{zebra1, zebra2} where Cat and Zebra are subclasses of Animal. Now Mehrdad proposed the following method to retriev...

How to unit test reading an Excel reader?

I have an ExcelReader class in my C# application - I need to import Excel spreadsheets into database tables. My problem is that this is one of the few untested classes - I cannot use a "mock input" for it, and testing with an actual Excel spreadsheet makes the test a bit slow (about one second). I know the class is working correctly - I ...

Rails: How do I write tests for a ruby module?

I would like to know how to write unit tests for a module that is mixed into a couple of classes but don't quite know how to go about it: Do I test the instance methods by writing tests in one of the test files for a class that includes them (doesn't seem right) or can you somehow keep the tests for the included methods in a separate f...

Test data sources in Android unit testing

I want to test parsing of data returned from server. I thought I might create several test XML files and then feed them to the sax parser which uses my custom data handler (as in the application that I test). But where should I put those test XMLs? I tried with [project_root]/res/xml, but then I get the error: android.content.res.Re...

FiddlerCore + autoresponder?

I have just discovered FiddlerCore (a .NET API to automate some Fiddler functionality) and I would like to use this in combination with Fiddler's autoresponder to run some automated testing given a set of predefined request-->response sessions (which is how autoresponder works, I believe). I cannot figure out how to set this up with Fid...

Using variables in Unit Tests - Value set in TestA is reset to default in TestB

I'm trying to write a bunch of unit tests for my classes, most of which are persisted. In my test class I have a bunch of member variables that contain the data that I'm pushing into my objects which are then created in the repository. One of the first tests is to create a record in the repository based on the data in the member variab...

Does TDD mean not thinking about class design?

I am making a role playing game for fun and attempting to use TDD while developing it. Many of the TDD examples I see focus on creating the test first, then creating objects that are needed to get the test to pass. For example: [Test] public void Character_WhenHealthIsBelowZero_IsDead() { // create default character with 10 health ...

JsTestDriver easy appending of elements to the body via :DOC syntax?

I'm using js-test-driver to test my Javascript code on several browsers: TestCase("DropDownValueReplacerTestCase", { setUp:function() { console.log("BEGIN: setUp"); /*:DOC += <form id="bob"></form> */ console.log("END: setUp"); }, tearDown:function() { console.log("BEGIN: tearDown"); ...

Unit Testing AssertError in JUnit

I'm trying to ensure that a parameter can't be null by adding an assert statement at the top of the method. When unit testing, I'm trying to declare that the AssertError is expected, but it still gets recognized as a failed test even though it's behaviour is correct (AssertError is getting thrown). class ExampleTest { @Test(expected...

Preparing unit tests : What's important to keep in mind when working on a software architecture?

Let's say I'm starting a new project, quality is a top priority. I plan on doing extensive unit testing, what's important to keep in mind when I'm working on the architecture to ease and empower further unit testing? edit : I read an article some times ago (I can't find it now) talking about how decoupling instantiation code from class...

rails test table doesn't exist after reverting migration

Hello, this is a very silly question I think: I just removed a table named person_emails I created a minute ago in a new demo app I created half an hour ago. Then I started testing like just now, when I ran a unit test on an unrelated model called line_item, and I got "ActiveRecord::StatementInvalid: Mysql::Error: Table 'depot_test.perso...

How Do I Describe 'Less Than Simple' Behavior (BDD) in Code?

Suppose that I am intending to draw some user-supplied text on a bitmap in C#, what sort of tests would I write up front? Is this sort of thing even possible? BDD seems very straight-forward when dealing with mathematical problems but I find it near impossible and more trouble than it's worth when dealing with custom UI controls, graph...

How to test methods that call other methods in a domain object

When working with Domain Objects, how do you typically unit test a method that calls another method in the object? For example: public class Invoice { public IList<InvoiceLine> InvoiceLines; public string Company; public bool IsDiscounted; public DateTime InvoiceDate; //... public GetTotalAmt(); public GetExtendedTotalAmt...