unit-testing

Basic NMock database examples for CRUD application

I'm looking for some basic examples of using NMock2 to mock database calls for a CRUD application. Thanks, Chris ...

How do I MOQ the System.IO.FileInfo class... or any other class without an interface?

I am writing a number of unit tests for a logger class I created and I want to simulate the file class. I can't find the interface that I need to use to create the MOQ... so how do you successfully MOQ a class without an interface? It also isn't clear to me how I can use dependency injection without having an interface available: priv...

Do Unit Tests target Multiple Cores in Visual Studio?

As our unit test numbers increase we are finding it increasingly difficult to continually run all the tests on our developer machines. Does anyone know if Visual Studio 2008: natively targets multiple cores doesn't target multiple cores automatically, but it's configurable doesn't target multiple cores at all ...

Writing unit tests for methods which have a degree of randomization

I'm using PHPUnit and my traditional approach is to use mock objects and methods that get called by the methods I'm testing. The mock objects are told what to expect as input by the unit test. The problem is that part of the input supplied to the mock objects are being randomly generated by the methods being tested (and the unit test has...

How to unit test private methods in BDD / TDD?

I am trying to program according to Behavior Driven Development, which states that no line of code should be written without writing failing unit test first. My question is, how to use BDD with private methods? How can I unit test private methods? Is there better solution than: - making private methods public first and then making th...

Testing MVC Controller Action HttpAcceptAttribute Verbs

What is the best way to unit test the controller action HttpAcceptAttribute verbs? So far I have the following but it's so ugly even a mother couldn't love it and not very flexible. Is there a better way? [Fact] // using xUnit, mocking controller in class public void FilterControllerTestRemoveFilterByProductAttributeIsOfTypePost() { ...

How to test the function behavior in unit test?

Hi Everyone, If a function just calls another function or performs actions. How do I test it? Currently, I enforce all the functions should return a value so that I could assert the function return values. However, I think this approach mass up the API because in the production code. I don't need those functions to return value. Any go...

Unit testing a method called during initialization?

I have a class like the following: class Positive(object): def __init__(self, item): self._validate_item(item) self.item = item def _validate_item(self, item): if item <= 0: raise ValueError("item should be positive.") I'd like to write a unit test for _validate_item(), like the following: ...

VS2008 Unit Tests: How to include a message with a "success"

Using Visual Studio 2008 for a unit test, one of the unit tests has to do with a basic performance smoke test to make sure additional code doesn't slow down a heavily-used method too badly. Obviously, I want this to fail when the "# per second" falls below a certain value, and of course it displays my message in the Error Message column...

QUnitAdaptor for JSTestDriver passing failed test!

Hi all: I have a very strange case here when using QUnitAdaptor to test my QUnit tests. It actually passed a test which is supposed to fail: test("very simple test", function() { var somevar = true; equals(somevar, false, "test"); }); The above test passed when I ran it after capturing browser programmatically. Has anyone experienc...

Mocking inter-method dependencies

I've recently started using mock objects in my tests, but I'm still very inexperienced with them and unsure of how to use them in some cases. At the moment I'm struggling with how to mock inter-method dependencies (calling method A has an effect on the results of method B), and whether it should even be mocked (in the sense of using a mo...

Visual Studio "Run a method" vs "Utility tests"

I use XUnit and Resharper to run my tests. In a given project I usually have a few utility tests which are not really tests but exist purely so I can execute a bit of code easily. For example, I have a test which outputs my NHibernate mappings (I use Fluent NHibernate) to a temporary directory. I don't really like having these as tests, ...

unit testing/ mocking static event handlers, what are the available options?

Im fully aware of the "problem" with static event handlers from a GC perspective so i'm not looking for advice on "DONT use static events" or anything like that, in my scenario this isnt a concern. I have a static class which has an event declared public static event EventHandler<MyEventArgs> FilePickedUpFromStorage; i have a client ...

How do I go about setting up a TDD development process with Google App Engine?

I'm primarily a Ruby guy, but lately I've been working on a lot of Python stuff, in particular, App Engine code. In Ruby, I'd use automated continuous integration (autotest), code coverage tools (rcov), static analysis (reek), and mutation testing (heckle) in my development process, but I'm not sure how best to set up a similar developm...

.NET Conditional Compiler Symbols and Unit Test Libraries

My team has a set of unit test libraries that run against our application code - unfortunately they are throwing (unexpected) exceptions. The reason for this is that our logging code is being called and the objects aren't setup. The logging code is executed via a method attribute we have setup using PostSharp (which get called before and...

NUnit. How to automatically generate tests?

Is there any software that simplifies creation of tests? Most of the contents of tests is pretty repetitive, so I thought someone might have automated this. ...

how to mock a parametrized constructor?

I've the following class. It has the code to connect to SAP in its constructor. There is an abstract method(the subclasses define the implementation) which I want to mock. public abstract class BapiExecutor { ... public BapiExecutor(final SapConnectionInfo connectionInfo) throws java.lang.Exception { if (!vali...

Run Jettys ServletTester within JUnit test

I'm trying to run Jettys ServletTester in my JUnit test. I created a simple HelloServlet first to test the setup, but I get an IllegalAccessException when I try to request the servlet. Here is what I have so far: My unit test @Before public void setUp() throws Exception { tester = new ServletTester(); tester.setContextPath("/co...

Is it possible to ignore certain unit tests?

Hi, I'm currently working on a project which uses JUnit4 extensively throughout all the modules. We're using Maven2 to build the project and Hudson for continuous integration. The project is built and run under Java 1.5. We've recently added quite a large raft of unit tests which are needed at times, but don't want to be run during the ...

How do I test for multiple exceptions with PHPUnit?

When testing for exceptions with PHPUnit, what is the best way to require that every statement or assertion must throw an exception in order for the test to pass? I basically want to do something like this: public function testExceptions() { $this->setExpectedException('Exception'); foo(-1); //throws exception foo(1); //d...