unit-testing

Reusing Generators in Different Unit Tests

I'm running into an issue while unit-testing a Python project that I'm working on which uses generators. Simplified, the project/unit-test looks like this: I have a setUp() function which creates a Person instance. Person is a class that has a generator, next_task(), which yields the next task that a Person has. I now have two unit-tes...

Is there a way to disable code coverage in PHPUnit for a single test?

Every time I run a single unit test in PHPUnit, a code coverage report is also generated. I have an older computer here at work, and if I could disable the code coverage when I don't need it, that would put less strain on my CPU. Is there a way to disable the code coverage on a per-test basis? I couldn't find any command-line switch tha...

Does NSubstitute support ref parameters?

I have the following method signature in my iterface: void SetItem(ref AddressItem item); I do a parameter constraint like this: IAddAddressForm form = Substitute.For<IAddAddressForm>(); AddressItem item = null; form.SetItem(Arg.Is(item)); But that fails because of the ref. If I take the ref out then it works fine. But I need to ...

Fluent NHibernate PersistenceSpecification can't test a collection of strings

I'm using Fluent NHibernate to map a a class that has a collection of strings like this: public class Foo { public virtual ICollection<string> Strings { get; set; } } public class FooMap : ClassMap<Foo> { public FooMap() { HasMany(f => f.Strings).Element("SomeColumnName"); } } When I write a unit test using the PersistenceSpe...

Android: How to transfer a test fixture file to device from unit test application

I'm writing an Android JUnit test and want to copy/reset a test fixture file (it's an SQLite database file.) If I were within the main application, I know I could just place the file in the assets directory and use getResources().getAssets().open(sourceFile) However, this API appears to be unavailable from the ActivityInstrumentationTe...

How to Mock (with Moq) Unity methods

Extension methods are not good for testing (that's described here: http://stackoverflow.com/questions/2295960/mocking-extension-methods-with-moq, http://www.clariusconsulting.net/blogs/kzu/archive/2009/12/22/Howtomockextensionmethods.aspx). But probably there are some solutions for mocking of Unity methods? In my case I have the followi...

Multiple testng.xmls in the same IntelliJ run configuration?

I have a project that has two different modules each with its own set of testng tests. I have separate run config's with code coverage enabled for each. I need to run both to gather coverage statistics and was wondering if there was a way to consolidate the coverage data in to a single session. Is it possible to create a run configura...

Testing C/C++ source code

Possible Duplicates: Suggestion for UnitTest tools for C++ Choosing a C++ unit testing tool/framework Unit Testing C Code This is something I've been wondering now that we have to use C/C++ as base language for some of our university projects : In Java there's JUnit, In PHP there's PHPUnit etc. How are unit testing don...

Designing unit test cases for an application which manipulates XHTML

I am working on an application which would take an XHTML. <documents> <document> <span class="style1"> This is some text1 </span> <span class="style2"> This is some text2 </span> <span class="style3"> This is some text2 </span> </document> </documents> The values for class attribute are basically styles. Those styles are ...

Final method mocking

Hi! I need mock some class with final method using mockito. I have wrote something like this @Test public void test() { B b = mock(B.class); doReturn("bar called").when(b).bar(); assertEquals("must be \"overrided\"", "bar called", b.bar()); //bla-bla } class B { public final String bar() { return "fail"...

How can I run OCUnit (SenTestingKit) with NSDebugEnabled, NSZombieEnabled, MallocStackLogging?

I have an error similar to the one in this post. Now, I'm sure I've made some stupid error somewhere, probably related to releasing an object or an observer or what-not, but since I can't seem to find a way to debug the code I thought I could use the NSDebugEnabled, NSZombieEnabled and MallocStackLogging (as shown here). Can it be done...

Mocking Javascript objects (specifically YUI)

Hi, I'm trying to mock YUI for javascript testing. I want to mock a datatable, but im not sure how to do it. Something like YAHOO.widget.DataTable = function(){ }; so latter I could do something like assert.that(returnedDatatable, isOfType(YAHOO.widget.DataTable)); ...

Testing... how do the pros do it, and what techniques can scale to single-person development?

I've been writing software for years, but have never mastered the art of testing. My typical testing includes thorough run-throughs on my machines, and then testing in various operating systems via VMware. Mainly a brute-force play-with-it-until-it-breaks-or-doesn't approach. Where possible I work on actual hardware, but this isn't al...

How to get NUnit to work with Visual Studio 2008

Maybe I am just forgetting something, but I cannot seem to get NUnit to work in Visual Studio 2008 Standard Edition. I am trying to use NUnit 2.5.7 in a C# class library project. I am following the structure of the samples given in the download of NUnit. Here are the steps I am doing 1) Download and install NUnit 2.5.7 2) Create C# cl...

log4Net issues with NUnit (Tried v2.5.7, 2.5.2, 2.4.8, 2.4.7)

I'm getting an error (see bottom of post) when running NUnit against a production code assembly. The production code assembly has a reference to a third party framework that uses log4net internally (Specifically, this is SimplyAccounting's SDK). The version of log4net that it uses is 1.2.9.0. Outside of this third party framework which w...

How do I write a unit test for this method in my view model in Silverlight without SecurityException?

I have a Silverlight testing project using the Silverlight Unit Test Framework. I want to test a method in my view model which takes FileInfo objects. This seems to work fine when I test it manually through the UI. Now I want a unit test just for the AddDocument method. I don't want to test actually clicking the button or simulate cl...

Challenges of refactoring unit-tests to be maintainable and readable when dealing with List<T> objects

In the book The Art of Unit Testing it talks about wanting to create maintainable and readable unit tests. Around page 204 it mentions that one should try to avoid multiple asserts in one test and, perhaps compare objects with an overridden Equals method. This works great when we have only one object to compare the expected vs. actual re...

How can I unit-test subflows in Spring Webflow 1.0?

Unit testing subflows in SWF 2.0 with mocks seems pretty straight forward, as Spring's reference clearly shows. My problem is with registering the subflow, because I can't find a way to access the flow definition registry using 1.0 API. Is there any way to register a subflow on the fly, in order to unit-test the flow? ...

In Ruby on Rails, do you test controllers and views or mostly models?

I have heard that at the very least, if you write unit tests for only models and try to keep the bulk of your logic in the model, you are pretty well off. Is there any merit to testing controllers and views or any other part of the framework? ...

Rhino Mocks: How to verify a method was called exactly once using vb.net and AAA syntax

I am trying to use the AAA syntax in Rhino Mocks with VB.Net to validate that a method was called only one time. I can't seem to get it right. With this code, if the repository is called twice, it returns nothing on the second call, and the test passes. I would have expected the test to fail when VerifyAllExpectations was called. <Te...