unit-testing

T2 testing

Hi all, I am doing some experiments with T2 on some old Legacy code; the problem is that the code has the tendency to throw IllegalArgumentExceptions. Does anybody out there have a good example on how to tell T2 to ignore these? Thx ...

Referencing a web service project from unit testing project: project not in list

Problem: Trying to reference a .NET 2.0 web service project from my VS unit testing project. Right click on the References folder in the unit test project -> Add Reference. The .NET 2.0 web service is NOT listed in the listbox of projects available to reference. I know this usecase is possible; I have previously successfully reference...

Test ASP.NET MVC routes using MVC Contrib

I'm trying to set up Route mapping tests using MVC Contrib as described in Test ASP.NET MVC routes using MVC Contrib The tests compile and execute, but they always fail with the message "The URL did not match any route." I set up another test to try to get an idea of what the problem is: Public Sub TestIndexRoute() Dim ro...

Free Testing / Code Coverage systems for C++

I'd like to start using a Test Driven Development system for a private project since I saw my employer using it and realized it was very useful. My employer's project was in C# but mines are in C and C++. I looked around and saw that several packages exist for both Java and .NET (for example: NCover, NUnit, ...). Unfortunately I found i...

Redirect both cout and stdout to a string in C++ for Unit Testing

I'm working on getting some legacy code under unit tests and sometimes the only way to sense an existing program behavior is from the console output. I see lots of examples online for how to redirect stdout to another file in C++, but is there a way I can redirect it to an in-memory stream so my tests don't have to rely on the disk? I'...

Mocking the instantiation of an object for a unit test

I am currently refactoring some code which performs Windows Impersonation for testability and have run into a bit of a roadblock. This is the bit of code that I am having trouble with: ... if (LogonUserA(user, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) > 0) { if (DuplicateToken(token, 2, ref to...

Unit testing silverlight where does this live?

Im tring to start unit testing with silverlight and some of the samples online use the following statements EnqueueCallback EnqueueConditional EnqueueTestComplete where do these live? ...

How to find undefined variables in PHP script

Suppose we have following function in PHP: public function testSomething() { $name = perform_sql_query("SELECT name FROM table WHERE id = $entity_id;"); assert($name == "some_name"); } Query is syntactically correct, but since $entity_id is undefined - query will always search for 'id = 0', which is semantically incorrect. I ...

How to mock GetType() method in NMock

Hi all, I have some production code like private bool IsTypeEqual(object theFirstObject, object theSecondObject) { if(theFirstObject.GetType()==theSecondObject.GetType()) { return true; } else { return false; } } Now i have to write the unit test case for this c...

Iphone Unit Testing error : permission denied with google toolBox

Hi, I followed many tutorial to set up a unit testing project for Iphone but i always get the same "permission denied" error when i build the project. Here is what i do : Get the latest source for Iphone Unit Testing Follow the instruction to set up the unit testing framework (Create a new project, add a new target, copy the necessar...

Mocking and Win32 API Calls

The current product I work on is a Windows Service written C++ and going forward all new functionality will have unit tests written for it. But this creates an interesting problem (for me at least) we do a lot Win32 calls for various things and behave accordingly, so for the unit tests to be complete it would be nice to test a variety o...

Connection string in unit test project to reference database in app_data folder

I am looking to reference my database file in my unit test project. This is an AP.NET MVC app. Please note: I know I should not be accessing the database in my unit tests but this is for a quick fix on one test that I need to have pass just now. After the next milestone I will be mocking the database access methods etc. So here is my ...

Delphi: How to use all units and unit references of one project in another project

I am building a dedicated project for all the unit tests of our main project, since including them in the main project would put a strain on an already huge codebase. Now all the units of the main project are referenced in the project's dpr file with their locations. When I write a testcase for a class I simply copy the classes unit refe...

Flex, Flexunit: How to test that an event is dispatched twice?

I'm testing some event dispatch code in a Flex app, using FlexUnit's addAsync method for testing that events are dispatched. Great so far, I can ensure that at least one event was fired. However, I want to be a bit more detailed; I want to ensure that exactly the set of events I'm expecting are dispatched. Is there a useful test patte...

Is there a detailed "how to" on Unit Testing for Visual Studio 2005

I have never written/run a unit test. I am a relatively young programmer, but I do a LOT of reading. I've been searching for information on unit testing because I see a lot about, but I haven't come across anything that has really spelled it out for me from step 1. I have Visual Studio 2005 Professional. I will be starting a new wi...

Unit Testing : How do I abstract the M to test the VM in MVVM when using RIA Services

Ok I'm having a crisis of conscience right now. I am having no luck in trying to abstract out RIA Services from our Silverlight application so we can do proper unit testing. At this point we have a views and view models, and DomainContext is the Model. No matter how much we tried we cannot find anyway to abstract the DomainContext or t...

Unit Testing: Logging and Dependency Injection

So regards logging from SO and other sites on the Internet the best response seems to be: void DoSomething() { Logger.Log("Doing something!"); // Code... } Now generally you'd avoid static methods but in the case of logging (a special case) this is the easiest and cleaniest route. Within the static class you can easily inject ...

Problems running unit tests after upgrading from Netbeans 6.5 to Netbeans 6.7

Hi All, I am experiencing issues with existing projects from Netbeans 6.5 in Netbeans 6.7 when selecting a file under "Test Packages" and performing a right click-->Debug, or right click-->Run. The error reported is: java.lang.NoSuchMethodError: main Exception in thread "main" Java Result: 1 I am using JUnit 4.x I have not changed ...

ExpectedExceptionAttribute is not working in MSTest

This is wierd, but all of a sudden the `ExpectedExceptionAttribute' quit working for me the other day. Not sure what's gone wrong. I'm running VS 2010 and VS 2005 side-by-side. It's not working in VS 2010. This test should pass, however it is failing: [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public voi...

testing with before_filter

Hi all i've developed before_filter - http://gist.github.com/138659 and in tests like test "should get index" do get :index assert_response :success assert_not_nil assigns(:articles) end i see test_should_get_index(ArticlesControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might hav...