unit-testing

Little-endian hex in GHKit diagnostic, why?

In the context of iPhone programming, I am using the GHKit for unit testing (gabriel / gh-unit on github). Here is a failing test assertion : GHAssertEquals(150, 15, @"someLimit"); and here is the diagnostic from GHKit (shows up in the Simulator and in the Xcode Console) : 2009-07-25 22:41:12.553 UnitTests[38404:3f07] Exception:...

How do I mock HttpResponseBase.End()?

I'm using Moq to create a mock object of HttpResponseBase. I need to be able to test that HttpResponseBase.End() was called in my library. To do this, I specify some text before the call and some text after. Then I check that only the text before the call to End() is present in HttpResponseBase.Output. The problem is, I can't figure out...

Running multiple test data on same set of test cases.

Hello, I am new to eclipse. I am using JUnit 4. and i have written a set up method in my class which extends Testcase where some initialization happens. I have some set of testcases in the same class. I have test data in zipped form and attached to work space. Currently i am able to run all test cases for a single test data. Somehow i w...

Java Unit tests on methods that use third parties libs that don't use Interfaces

I'd like to know how do you test your methods if the libs you are using don't use Interfaces My class is like private ThirdParyClass thirdPartyClass; void myMethod() { AnotherThirdPartyClass param = "abc"; ... thirdPartyClass.execute(param); } I want to test that execute is called with the "abc" param. I was thinking in creating M...

Is there a way to customize the Unit Test Wizard in Visual Studio Team System?

I am tired of Unit Test Wizard on Visual Studio, it helps a lot, for sure, but there are some things that I always have to change, like replacing explicit variable typing by "var". There is a way to customize it? ...

Large Amounts of Setup Code: Does it indicate a problem and what stratergies exist to deal with it.

A part of my project interacts with iTunes using COM. The goal of the test in question is to verify that my object asks the iTunes API to export all of the album artwork for a collection of tracks to a file. I have successfully written a test which can prove my code is doing this, however to accomplish that I have had to stub out a chun...

Maven EAR module and EJB dependencies tests

We are building our EAR & EJB projects with maven. It will build all the EJB projects and then they are used as the dependency for EAR, so they are packed into the EAR file eventually. The problem is that each EJB project has junit tests that check the EJB. For now these tests are not very useful because they try to connect to applicati...

Why does my Moq IEventAggregator verification fail?

I use Composite WPF(Prism) and I am trying to unit test that my Controller does in fact subscribe to a Composite Event. My subscription code looks as follows... //Init Events. this.eventAggregator.GetEvent<PlantTreeNodeSelectedEvent>().Subscribe( ShowNodeDetails, ThreadOption.UIThread); My unit testing code looks as follows (I us...

Moq custom IIdentity

Hi, I created a custom RoleProvider (standard webforms, no mvc) and I would like to test it. The provider itself integrates with a custom implementation of IIdentity (with some added properties). I have this at the moment: var user = new Mock<IPrincipal>(); var identity = new Mock<CustomIdentity>(); user.Setup(ctx => ctx.Identity).R...

Unit testing custom RoleProvider with Moq?

I created a custom RoleProvider in a custom library. I would like to unit test it. Via Moq I created a fake HttpContextBase. How to pass this to the to be tested RoleProvider? The Identity is a custom test implementation class. This works fine. I only don't know how to pass in the fake context in my provider. This is not an MVC applicat...

MVC Unit Testing, accessing model sent to View

Hi, I have the following method in one of my Views, public ActionResult EditRoute(int? id) { // Do Work return View(new RoutingFormViewModel(obj1, obj2, obj3)); } What I'd like to do is get the RoutingFormViewModel that is being passed to the view in my unit test, is this possible? I've tried the following but don't seem to ...

Iphone Unit Test : with SQL

Hi, I'm trying to do some Unit Testing on method that includes SQL call wrapped by FMDB. I get a lot of linker errors when i try to build the project such as these ones : "_sqlite3_step", referenced from: -[FMResultSet next] in FMResultSet.o -[FMDatabase executeUpdate:arguments:] in FMDatabase.o "_sqlite3_column_name", ...

adjusting constants in static class for unit tests in C#

I have a static class representing a connection pool that I want to unit test using Visual Studio 2008's built-in unit testing framework. The static class has some constants in it, like for the maximum allowed connections. I want to decrease this value for my unit test so I don't have to have a lot of connections open in order to hit a...

Clearing the test database between unit and functional tests in Rails (factory_girl)

Recently I switched from fixtures to factory_girl to test my Ruby on Rails application. If I run rake test:units, to run the tests in my /units directory, they all run perfectly. The same is true if I run my functional tests (in my /functional directory) with rake test:functionals. However, if I simply run rake test, to run both my unit...

Are there situations where unit tests are detrimental to code?

Most of the discussion on this site is very positive about unit testing. I'm a fan of unit testing myself. However, I've found extensive unit testing brings its own challenges. For example, unit tests are often closely coupled to the code they test, which can make API changes increasingly costly as the volume of tests grows. Have you fo...

How do I write NUnit unit tests without having to surround them with try catch statements?

At my company we are writing a bunch of unit tests. What we'd like to have done is for the unit tests to execute and whenever one succeeds or fails at the end of the test we can write that somewhere but we don't want to put that logic in every test. Any idea how we could just write tests without having to surround the content of the te...

create initial data for hibernate driven testing

Hello good people! first of all thank you all for reading this. i want to populate my database (derby) every time i run the test class to be able to perform test like delete or update or deletebyid stuffs. I use <property name="hibernate.hbm2ddl.auto">create</property> in my hibernate.cfg.xml file so i'm expecting the database to be ...

How do I listen to a mocked object's event?

I'm doing some unit tests for a controller, and I'm mocking the business component. The BC has a public event that I have the controller listening to when the controller is constructed. The problem I'm having is I keep getting an Expectation error stating: "IBC.add_MessageRaised(MessageEventHandler) Expected#:1 Actual#:0". However, I ...

Python's unittest and dynamic creation of test cases

Is there a way to dynamically create unittest test cases? I have tried the following.. class test_filenames(unittest.TestCase): def setUp(self): for category, testcases in files.items(): for testindex, curtest in enumerate(testcases): def thetest(): parser = FileParser(curtest...

In Visual Studio, is there a way to generate unique method names automatically?

I'm writing a bunch of tests for a class, and frankly I don't want to go to the effort of naming each test intelligently: "Compare2002to2002forLessThanOrEqual" I'm cool with TestMethod1 through TestMethod120 - but I've got to edit each name, and that gets annoying. Is there any plugin that will generate unique names for all the methods...