unit-testing

Correct way to unit test private variables

I have the following method: private string _google = @"http://www.google.com"; public ConnectionStatus CheckCommunicationLink() { //Test if we can get to Google (A happy website that should always be there). Uri googleURI = new Uri(_google); if (!IsUrlReachable(googleURI, mGoogleTestString)) { //The internet is...

Speeding up RSpec tests in a large Rails application

I have a Rails application with over 2,000 examples in my RSpec tests. Needless to say, it's a large application and there's a lot to be tested. Running these tests at this point is very inefficient and because it takes so long, we're almost at the point of being discouraged from writing them before pushing a new build. I added --profile...

Android Techniques for Mock Data Source in Activity Unit testing

I'm fairy new to unit testing and I've been learning how to use the jUnit framework for android(using ActivityInstrumentationTestCase2) but I'm having trouble working out how to I inject a mock data source into and activity, example: in the activiy I have this public void onCreate(Bundle savedInstanceState) { super.onCreate(sav...

How can I use TestSuites with Junit4?

I can't seem to find any documentation on how to do this that actually explains how to invoke the testsuite. So far I have this: package gov.hhs.cms.nlr.test; import java.util.LinkedList; import org.junit.runner.RunWith; import gov.hhs.cms.nlr.test.marshalling.InquiryMarshallingTest; import junit.framework.Test; import junit.fra...

How can I use unit testing when classes depend on one another or external data?

I'd like to start using unit tests, but I'm having a hard time understanding how I can use them with my current project. My current project is an application which collects files into a 'Catalog'. A Catalog can then extract information from the files it contains such as thumbnails and other properties. Users can also tag the files with...

How to write such unit test?

Hi everyone, Now i'm expericing a problem about unit test, We have developed a platform with C++, and this platform include 2 layers, one is engine layer, the other one is widget layer, and i'm a dev in widget layer, The widget layer used by client app (those app is our product), now the problem is this: 1, We want to add some unit t...

Testing a query builder

I am building a query builder that I want to unit test. I don't know how to go about it though. It (currently) consists of two parts: the QueryBuilder itself which provides a fluent interface for constructing queries. And a SqlConstructor that takes care of constructing the actual SQL. So basically, how do I test 'correctness'? Should ...

How to integrate Sikuli scripts into Selenium?

I'm extensively using Selenium for integration testing. Works great for all normal stuff (HTML/AJAX), but no go when I'm trying to test third party ActiveX, Java applets and Flash components. The solution I've found for this is Sikuli. Works great locally, but how can I integrate that into Selenium? btw. if that's relevant, for Seleni...

Build failure in unit test project with accessors of a project containing covariant types

Hello folk, Lets start at the beginning :) I added a covariant interface to our project: interface IView { } interface IPresenter<out TView> where TView : IView { TView View { get; } } I created some classes, implementing these interfaces: class TestView : IView { } class TestPresenter : IPresenter<TestView> { public TestVie...

Unit testing entity framework

When unit testing with NHibernate I will typically have tests that create and save an object, clear the session (session.Clear()) then retrieve the object from the database. What's the equivalent of Session.Clear() with EF4? Example test: [Test] public void Can_create_and_save_a_default_account() { var account = ne...

When running mstest against a WCF service, WcfSvcHost fails to run and tests fail. Tests pass when debugged.

Using Visual Studio 2010, I have written a simple WCF service and some integration tests that I want to run against it. I build my proxy for the tests at runtime in code rather than using configuration. My tests pass in debug but not when run! FAIL if run - go Test/Run/Tests in current context ( as the WCF Service it calls has not bee...

Moq and constructors - testing initialisation behaviour

I'd like to be able to test a class initialises correctly using Moq: class ClassToTest { public ClassToTest() { Method1(@"C:\myfile.dat") } public virtual void Method1(string filename) { // mock this method File.Create(filename); } } I thought I'd be able to use the CallBase property to...

Grails Controller Testing - Problems with dynamic methods

Hi, I'm running some old (but valid, i'm told) tests on a legacy application, and notice that many of them arent working. The error message usually is 'No method signature for some dymamic method' After using mockDomain I managed to solve that problem. However, I can't figure out how to test controllers that create objects inside. Fo...

Access image in my Android Tests

Hi, I am working on an Android app. It has corresponding spec/test application. As part of some of my tests, I need to pick up an image from my assets folder and calculate SHA-1 for it. I can calculate SHA, as long as I can pick the image. Since the tests run on emulator; I am not sure how to pick the image in my test. Does anyone hav...

Django Testing: determine which view was executed

In the Django testing documentation they promise that you can "Test that the correct view is executed for a given URL." However I didn't find any possibility how to test which view was executed. I would expect that in the Response class but there's nothing about the executed view. Thanks in advance. ...

How to test if a fluent service method is called

I have a security rule that a newly registered user has full permissions over their own user entity. I'm using Rhino.Security and the code works fine, but I want to create a unit test to make sure the appropriate call is made to setup the permission. Here is a simplified verison of the code: public User Register(UserRegisterTask userR...

Testing IDisposable and WCF client

Usually I have client code similiar to something like this: // SomeOtherServiceClient would be injected in actual code. ISomeOtherService client = new SomeOtherServiceClient(); ... so that I can mock the service for testing. But now I have a WCF service that has the context mode set to PerSession and implements IDisposable. [Service...

Trace source of deprecation warnings in rails tests

When running my functional tests, I'm getting the following warning in one of the test cases but I can't pinpoint where it's coming from: gems/actionpack-2.3.8/lib/action_controller/record_identifier.rb:76: warning: Object#id will be deprecated; use Object#object_id Unfortunately that's the only line of the backtrace that's shown, even...

Is there a way to Run MS Test using Gallio?

I have looked at other questions similar to this and they all seem to be Pre-RTM of Visual Studio 2010 (or they don't have a real answer). I have downloaded the latest version of Gallio and I am trying to run my MS Test Project using it. I added Gallio to my References in my MS Test Project then did a full build and then opened the com...

What are some good examples of open source projects developed in a test-driven fashion?

I found http://stackoverflow.com/questions/2893841/open-source-projects-with-good-quality-tests but I wanted to ask something a bit different. I'm having a hard time visualizing how to build production code using TDD practices, particularly for networked database-driven applications where big chunks of functionality are dependent on one...