unit-testing

How to avoid duplicating test code

I have written my units tests, and where external resources are needed it is dealt with by using fakes. All is good so far. Now i' am faced with the other test phases, mainly integration where i want to repeat the unit test methods against real external resources e.g The Database. So, What are the recommendations for structuring tes...

Is this a poor design?

I'm trying my hand at behavior driven development and I'm finding myself second guessing my design as I'm writing it. This is my first greenfield project and it may just be my lack of experience. Anyway, here's a simple spec for the class(s) I'm writing. It's written in NUnit in a BDD style instead of using a dedicated behavior driven fr...

Rails 2.3.2 unit test passes when run with normal ruby, fails when run with rake test:units

Hi folks, When creating a record in a unit test, I'm getting an 'ActiveRecord::RecordInvalid' when it's run with rake test:units. I don't get this error when I run the unit test manually with ruby ('ruby unit/blah_test.rb'). I've narrowed the issue down to a validation that exists in my model. It is an inclusion validation which is a...

How to load fixtures only once in django unit tests ?

In unit tests i need to load few fixtures this i have done as below class TestQuestionBankViews(TestCase): #load this fixtures fixtures = ['qbank',] def setUp(self): login = self.client.login(email="[email protected]",password="welcome") def test_starti...

mock problem

//IsExist always false,is it a bug? [TestMethod] public void IsExist() { private Mock<IRepository> repository = new Mock<IRepository>(); Foo f = new Foo(); repository.Expect(s => s.IsExist(foo)).Returns(true); var controller = new MyController(repository.Object); var res...

Anybody knows how to test ICommand properties using Silverlight UT framekwork?

I download command behavior from web and have implemented in my silverlight project. Now I am trying to figure out how to unit test ICommand properties. I know lots of people are working on this, so if you have a good simple example of unit testing ICommand, please let me know. Thanks Dev ...

Why is it not possible to inherit tests methods from other assemblies

WHy is it not possible to inheritance tests from other assemblies to run: namespace TestProject.Base { [TestClass] public abstract class TestBaseClass { [TestMethod] public void BaseTest() { Assert.IsTrue(false); } } } Test Runner namespace TestProject.UnitTest { [...

How to test WCF timeout settings?

Hi, How can I unit test the effect of each WCF timeout setting? I want to ensure that I select good values and I also want to make sure that my exception handling code is solid. I created client program and a server WCF service to test the timeout settings. In my service implementation, I added a Thread.Sleep(5000). On the client-side,...

linq to sql insert query not working from unit test project

I'm having a strange behavior in Linq to Sql... I have a simple parent | child (one to many) object model. In my app, I create the parent object and populate the children all in memory, and then call my repository's add method to insert both the parent with its children. Now from my application (winform), all works correctly as expect...

Does a framework like Factory Girl exist for Java?

Factory Girl is a handy framework in rails for easily creating instances of models for testing. From the Factory Girl home page: factory_girl allows you to quickly define prototypes for each of your models and ask for instances with properties that are important to the test at hand. An example (also from the home page): Factory....

Mock SSL HttpRequest for Unit Testing

I'm trying to mock out an SSL HttpRequest but I'm having trouble figuring out how to set the protocol to HTTPS in the request object. I got started from an example from Phil Haack here: http://haacked.com/archive/2005/06/11/simulating_httpcontext.aspx Is there a way to set the request to SSL? public class MockHttpRequest : SimpleWorke...

BeforeClass using Spring transactional tests

I'm using the Spring transactional test classes to do unit testing of my DAO code. What I want to do is create my database once, before all the tests run. I have a @BeforeClass annotated method but that runs before Spring loads up the application context and configures the jdbcTemplate, thus I don't actually have a connection to the DB ...

Using doctest "result parser" within unit-tests in Python?

I recently faced a problem about combining unit tests and doctests in Python. I worked around this problem in other way, but I still have question about it. Python's doctest module parses docstrings in a module and run commands following ">>> " at the beginning of each line and compare the output of it and those in docstrings. I wonder...

Has anyone successfully run integration tests with Jboss embedded, Seam and Maven?

Have been trying to get integration testing working with my seam project and the Jboss embedded container but am not having much success. Have been doing a lot of reading and have been trying what is mentioned in this JIRA but am not having any luck. Amy currently just trying to get the 'testproject-master-JBSEAM-2371.zip' project work...

Groovy: Verify construction of stubbed URL

The test class below verifies that a simple HttpService gets content from a given URL. Both the implementations shown make the test pass, though one is clearly wrong because it constructs the URL with an incorrect argument. To avoid this and correctly specify the behaviour I want, I'd like to verify that in the use block of the test ca...

Using MOQ to test controller

I'm having trouble writing a unit test for one of my controller actions. Here's the details. This view is strongly typed: Inherits="System.Web.Mvc.ViewPage<IEnumerable<Request>>" Here is the method in the controller under test: // GET: /Request/List public ActionResult List() { return View("List", r...

Unit testing MVC routes that POST

I have 2 routes registered as follows: routes.MapRoute("GetAnEmail", "{controller}", new { controller = "Home", action = "GetAnEmail" }, new { httpMethod = new HttpMethodConstraint("POST") }) routes.MapRoute("Home", "{controller}/{action}", new { controller = "Home", action = "Index" }) I have a valid unit test for the Home controller...

Visual Studio Unit Tests Missing During "Run Tests in Current Context"

...except it isn't missing. I just wrote it, decorated it with [TestMethod] and can see it right in front of me and it compiles. It just doesn't show up in the test results window when running all the TestMethods in the containing TestClass. Or when my cursor is on it making it the only test in the current context. In that case, all the ...

How to exclude ancestors when calling Assert.IsInstanceOfType?

We've just separated our SQL Server database adapters to allow for differences between SQL Server 2000 and 2005, specifically, the nvarchar(max) data type. Because the code change is so small, instead of reimplementing our adapter interfaces and abstract base class, I subclassed the SQL 2005 adapter from SQL 2000 and just override the a...

How to migrate a nunit-config-file to mstest?

I would migrate all my unit tests from nunit to mstest. In the solution I have a nunit-config file, which looks like that: <NUnitProject> <Settings activeconfig="Web"> <Config name="Web" appbase="Web" configfile="web.config" binpathtype="Auto"> <assembly path="bin\Product.NUnit.ComponentA.dll"/> <assembly path="bin\Product.NUnit...