unit-testing

Confused about testing an interface implementing method in C++.. how can I test this?

Please, consider the following (I'm sorry for the amount of code; but this is the minimal example I could think of...): class SomeDataThingy { }; struct IFileSystemProvider { virtual ~IFileSystemProvider() {} //OS pure virtual methods } struct DirectFileSystemProvider { //Simply redirects the pure virtuals from IFileSystem...

Why this xUnit test fails?

Assert.Equal(1000000.0, table.Convert("g", "mcg", 1.0)); // Pass Assert.Equal(2000000.0, table.Convert("g", "mcg", 2.0)); // Pass Assert.Equal(3200000.0, table.Convert("g", "mcg", 3.2)); // Fail // The failing one is equal to doing the following calculation, which fails also: Assert.Equal(3200000.0, 3.2 * 1.0 / (1.0 / 1000000.0)); // Fa...

PHPUnit code coverage not working with configuration

I have my PHPUnit setup and coverage report working fine without a white list filter. Once I add one however, the report seems to only partially generate as if PHPUnit quit unexpectedly. I do not get any errors or warnings. My configuratoon looks like this: <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="./bootstrap.php" ...

Check that a function raises a warning with nose tests

I'm writing unit tests using nose, and I'd like to check whether a function raises a warning (the function uses warnings.warn). Is this something that can easily be done? ...

ruby rails functional test problem

I'm getting the following problem with my functional test. mrbernz:mylife bernardleung$ ruby test/functional/forums_controller_test.rb ..... 1) Error: test_should_create_forum(ForumsControllerTest): ActiveRecord::StatementInvalid: Mysql::BadFieldError: Unknown column 'id:3 name' in 'field list': INSERT INTO roles (id, id:3 name) VALU...

Unit testing functions with side effects?

Let's say you're writing a function to check if a page was reached by the appropriate URL. The page has a "canonical" stub - for example, while a page could be reached at stackoverflow.com/questions/123, we would prefer (for SEO reasons) to redirect it to stackoverflow.com/questions/123/how-do-i-move-the-turtle-in-logo - and the actual r...

PHPUnit: Failed asserting last controller used <"error">

Hi, I am working on a ZF project wich use a postgre database, on my local server (ubuntu 10.04 LTS Lucid Lynx). I'm trying to run a very simple test with phpunit: public function testIndexAction() { $this->dispatch('/'); $this->assertController('index'); $this->assertAction('index'); $this->asse...

What should, and shouldn't, be covered by unit tests?

Clearly, I don't understand unit testing. This is fine, considering I've never done it before. I'm starting a new project, and wanted to bake unit testing into it from the beginning, so I'm looking to learn. I had always equated unit testing with code coverage, thinking that you should have unit tests which cover every function/method i...

How to make integration test for DB at google App. engine?

Hi overflowed. I'am wondering, how to write integration tests, that involves DB interaction, for Google app engine? It's seems - no problem to run this test at Google, on "live" db, using GAEUnit SO Thread But, this seems bad practice to me, because it's live environment. Google has provided examples of such tests, for java, but not fo...

Types of methods which are hard to unit test?

Hi, What unit tests generally tend to be hard to write and why? I am particularly interested in methods which don't need mocking. Thanks ...

Should unit tests know about NHibernate?

I'm following on from a previous question. The answer I accepted involves using a generic IRepository to handle basic CRUD, wrapped with a domain specific IMovieRepository which delegates to the generic setup. A further detail involves having a WrapQueryInSession method on the generic IRepository: IEnumerable<T> WrapQueryInSession(Func<...

WebTest: Testing with decorators + datastore calls

Hello, I have a Google App Engine application and my request hadnler has a decorator that does authentication. With WebTest I found out yesterday how you can set a logged in user and administrator. Now today my authentication decorator got a little more complex. It's also checking if a user has a profile in the database and if he doesn...

How can I run Microsoft Visual Studio Units Tests in an automated way using .NET code?

We have a build and deployment tool and as part of the tool before a deployment I want to validate that all of our unit tests run. I want to execute the Visual Studio unit tests using C# code if possible in some way. These tests were not built for nunit. Are there any good articles or ways of doing this that someone could recommend? ...

Unit test not reaching a piece of code

I am new to unit testing. I want to do something as follows: [Test] [ExpectedException(ExceptionType = typeof(Exception))] public void TestDeleteCategoryAssociatedToTest() { Category category = CategoryHelper.Create("category", Project1); User user; Test test1 = IssueHelper.Create(Project1, "summary1", "description1", user);...

Failing an entire context with Shoulda Unit Tests

Using shoulda with unit/test I have a context which requires one test to pass before the others are even tried. Is there a method I can invoke which will fail all following tests in the current context? Or not even run them? I'm imagining something like: context "My thing" do setup do my_variable = false end should "have my...

Am I doing something fundamentally wrong in my unit tests?

After reading an interesting article about unit testing behavior instead of state, I came to realize that my unit tests often are tightly coupled to my code because I am using mocks. I cannot image writing unit tests without mocks but the fact is that these mocks are coupling my unit test very much to my code because of the expect andRet...

Unit Testing with Shoulda

edit: this problem only happens sometimes This only appears to happen when I run the test from within TextMate (even when I specify the ruby to run it from by hand with a shebang). If I run it from the terminal then everything is peachy… Here's some code: require 'test/unit' require 'shoulda' class TestingTest < Test::Unit::TestCas...

Leaf classes in the dependency graph can only be tested for state?

So, I was thinking and I came into the conclusion that when Unit-Testing, even if one wants to base mainly in behaviour-type testing (that is, with mocks, for example), I will eventually always to have to do state-based testing at least for the leaf classes (in the dependency graph). Is this correct? PS: I am, of course, excluding stab...

Couple of questions about unit-testing

Let's assume we are designing a Stack class test-first (TDD): public class Stack<T> { private T[] elements = new T[16]; private int size = 0; ... } This Stack makes use of a size 16 internal array to store its elements. It will work fine until you need to add a 17th element. As I might need a 17th element, I decided to add...

How to conciliate TDD with SUT interface's contracts?

Assuming we are implementing using TDD a Stack class, we would need, for each bit of functionality of our Stack class, to add a new test that exercises it: [TestMethod] public void Should_Be_Empty_After_Instantiation() [TestMethod] public void Should_Not_Be_Empty_After_Pushing_One_Item() ... Now, on the other hand, when doing Unit-Tes...