unit-testing

Machine.Specifications and Entity Framework Examples

I'm trying to find some best-practice examples (or any examples, actually) of using Machine.Specifications with the ASP.Net Entity Framework in an MVC project. Not having had much experience with Machine.Specifications, I'm keen to see what sort of tests other people find useful and whether there are any gotchas for using the EF-generat...

What's the best way to test this?

I'm going through the EdgeCase Ruby Koans. In about_dice_project.rb, there's a test called "test_dice_values_should_change_between_rolls", which is straightforward: def test_dice_values_should_change_between_rolls dice = DiceSet.new dice.roll(5) first_time = dice.values dice.roll(5) second_time = dice.values ...

How to access private class fields from a test using UnitTest++?

Hello all, I'm facing a nuisance when coding my unit tests using UnitTest++. I'm wondering how to access private member class fields in a clean way (or maybe any way...) By now, I have a solution to access protected members using a class fixture deriving from the class under test. The following code shows the idea: struct MyFixture : C...

Unit testing with singletons

I have prepared some authomatic tests with the Visual Studio Team Edition testing framework. I want one of the tests to connect to the database following the normal way it is done in the program: string r_providerName = ConfigurationManager.ConnectionStrings["main_db"].ProviderName; But I am receiving an exception in this line. I supp...

How to test Rails :helper_methods that live in application.rb?

Here's my situation - I have a helper named LayoutHelper that I use to help me build my layout, and I'm trying to test the following method. It has a method in LayoutHelper that looks similar to this: def show_login_form? return false if @hide_login_form || logged_in? return true end I also have the following in my application.rb...

Run tests from inner classes via Maven.

I have following tests structure: public class WorkerServiceTest { public class RaiseErrorTest extends AbstractDbUnitTest{ @Test public void testSomething(){ } ... } ... } It's done because I don't want to create a separate class file for every test case extending AbstractDbUnitTest. Th...

Is it good practice to use Entity Framework in unit tests?

I'm writing NUnit tests for a service. I've decided to do this by sending direct SQL statements to the database instead of using the Entity Framework model so that I could be certain of the results, i.e. I am testing what is in the database and not what the Entity Framework tells me is in the database (e.g. it could be reporting a cache...

Commit in git only if tests pass

I've recently started using git, and also begun unit testing (using Python's unittest module). I'd like to run my tests each time I commit, and only commit if they pass. I'm guessing I need to use pre-commit in /hooks, and I've managed to make it run the tests, but I can't seem to find a way to stop the commit if they tests fail. I'm ru...

ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest

I have a test case: class LoginTestCase(unittest.TestCase): ... I'd like to use it in a different test case: class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() This raises: ValueError: no such test method in <class 'LoginTest: runTest` I looked at the unittest ...

Objective-C Unit Tests cannot find my resources

When i run unit tests it fails on loading external resources (images) with the same error as if they don't exist. In xcode i have added the resources to the unit test target. I don't know what to try next. I am using the Cocos2d framework, I try to load the following code within a unit test AtlasSpriteManager *at = [AtlasSpriteManage...

In Rails controller tests, Is there a way to simulate a specific remote IP?

Some functionality in my app works differently depending on the client's IP address. Is there a way to test that in Rails functional tests? I'm using Test::Unit and Shoulda. ...

Unit Testing for Smart devices using framework 2.0

VSTS 2008 (Visual Studio Team System) is coming with inbuilt Unit Testing Feature. We can add a test project to perform unit testing over the Smart device project. The problem comes when my smart device project is not using Framework 3.5 but over Framework 2.0. I strictly not to install Framework 3.5 in the device. But this restriction ...

Reporting unit test results.

I am writing a paper for a scientific conference. Just to be thorough, in that paper I said I made unit tests for the components in the system among all the other tests (system testing, usability etc) I made. In the results section, for the unit tests I simply said that all the tests passed. I submitted the draft to my adviser and now ...

NUnit, TestDriven.Net: Duplicate test results with partial test classes

I just discovered that I was getting twice the number of tests run that I should've been getting. Discovered it when a test broke and I got two identical test failures. Same test, same everything. Got me quite confused, but managed to narrow it down to a certain test class that was a partial class. The reason it was a partial class was ...

Automated Silverlight Unit Testing with CruiseControl.NET

What is currently the best solution to automate running unit tests against silverlight applications within CruiseControl.NET? Preferably I would like to run MSTest unit tests however as these aren't officially supported for silverlight yet I am open to suggestions that use other testing frameworks. ...

Android Unit Tests Requiring Context

I am writing my first Android database backend and I'm struggling to unit test the creation of my database. Currently the problem I am encountering is obtaining a valid Context object to pass to my implementation of SQLiteOpenHelper. Is there a way to get a Context object in a class extending TestCase? The solution I have thought of i...

how to unit test following Method, returnig value using "ref"

I have similar methods, in the Business layer. New to unit testing and sometimes get confused. For an idea, can you suggest, what will be a better approach to test this method behaviour? I am using C# NUnit and Moq public int? AddNewCatRetID(string categoryName) { int? categoryID = 0; Adapter.AddNewBlogCategoryReturnID(categ...

Mocking 3rd party callback events using moq

We've been trying write unit tests for a worker class written in C#, which mocks out a third party API (COM based) using moq to dynamically create the mock objects. NUnit is our unit testing framework. This third party component implements a couple of interfaces, but also needs to call back into our worker class using events. Our plan w...

Unit Testing with WatiN and NUnit

It seems that the common theme among SO questions regarding WatiN have to do with actually getting the thing working and I'm no exception. I've downloaded the latest release of WatiN (2.0.20.1089) and am trying to create the NUnit / WatiN equivalent of Hello, World: using WatiN.Core; using NUnit.Framework; namespace Foo.Browser.Tests ...

Is there a unit testing framework for GNU make?

There is a number of unit test frameworks for most of the languages, but I haven't come across a unit test for GNU make. It has conditionals, loops (the $(foreach ...) statement), and allows to write pretty sophisticated code. The examples might be things like BSD ports, GARNOME, and OpenCSW GAR. There's also a debugger for GNU make....