unit-testing

Creating DOM structure using jQuery for unit testing

Hi all: Suppose I have the following html: var testString = ' <span id='id'> <div> <table> <span id='anotherId' class='NODE customContext' name='2'></span> </table> </div> </span>' and I want to convert it to a DOM structure using jQuery (under the assumption that jQuery is the best option to handl...

Is there a way to put an assertion on an event?

Can I test the assertion that an event was fired? Something like this: [TestMethod] public void EventFiresWhenChangingProperty() { var sut = new SystemUnderTest(); var eventRegister = new EventRegister(sut.PropertyChanged); sut.AnyProperty = "new value"; Assert.EventWasFired(eventRegister); } Of course I could create a...

How to access Dispatcher in Silverlight tests?

I am using the SL unit test framework for tests (http://code.msdn.microsoft.com/silverlightut). My code is heavily client-server communications dependant, and I access the GUI dispatcher in several places to make sure important data is only accessed on a single thread (ie. the GUI thread). This dispatcher seems unavailable in the unit t...

Unit testing Zend controllers with mock models and services

I've read a lot of Zend controller testing tutorials but I can't find one that explains how to test a controller that uses models and mocking those models. I have the following controller action:- function indexAction(){ // Get the cache used by the application $cache = $this->getCache(); // Get the index service client and mod...

Run nosetests with warnings as errors?

When running nosetests from the command line, how do you specify that 'non-ignored' warnings should be treated as errors? By default, warnings are printed, but not counted as failures: [snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add() self.session.save(state) [snip]/service/accounts/database.py:97: SADe...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed with MS VS 2008 pro)! ...

Database not dropped in between unit test

Hello good people i came accross a weird behaviour in my test.I'm using JPA hibernate annotation with spring. let say i have an Class MyObject and it's property email is marqued @Column(name="EMAIL", length=100, unique=true) private String email; i prepare for what i need to be in the database in the setup of this class MyObjectDAOImp...

XPath, Selenium: Element is found in XPath checker but not in Selenium!?

I have the following XPath: //div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href When I try out this XPath in XPath Checker (Firefox extension), it works perfectly all the time. But when I do the following in Selenium: System.out.println(selenium.getAttribute("//div[contains(@id, 'box')]/div/h4/small/a[contains...

Unit testing for failed malloc()

What is the best way for unit testing code paths involving a failed malloc()? In most instances, it probably doesn't matter because you're doing something like thingy *my_thingy = malloc(sizeof(thingy)); if (my_thingy == NULL) { fprintf(stderr, "We're so screwed!\n"); exit(EXIT_FAILURE); } but in some instances you have choices o...

is this possible to do with iBatis + spring

usual idiom of using ibatis with spring support is following. Or this is how I'm doing it. please let me know if it can be done a better way? beans xml: <bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="jdbc/some/som1/my/mydb"/> </bean> <bean id="SqlMapClient" class="org...

FactoryGirl/machinist equivalent in c#/.Net

Rails has very nice way to generate test data with factoryGirl/Machinist +Shoulda . from factorygirl site "Factory Girl provides a framework and DSL for defining and using factories to create data records for ruby test suites. The goal is to be less error-prone, more explicit, and all-around easier to work with than Rails’ fixtures." ...

Linker Error: iPhone Unit Test Bundle referencing App classes

Starting with an app already in development, I have carried out the instructions in the iPhone Development Guide – Unit Testing Applications I can successfully include and use my App's classes in Application-style tests that run on the device, and output their results to the console. If I add the following line of code: STAssertTrue([...

how to assert response success in groovy unit testing

Hey i am trying to develop a sample app in groovy on grails...i have an action called login..which doesn't do anything except to render a page called login...I think there is no need to explicitly render any view called login inside the action, as my view name matches the action name. def login = { } As i follow TDD..I want to assert...

How can I separate different sorts of Perl tests so I don't have to run them all?

I noticed that in Perl the custom is to stick all tests into the t directory. How do you separate the unit test from the functional ones? Or, to make the question simpler and more obvious, how do you separate the tests that run quickly from the ones that do not? When all the tests run together the testing takes too long to be routinely u...

Unit test for thread safe-ness?

I've written a class and many unit test, but I did not make it thread safe. Now, I want to make the class thread safe, but to prove it and use TDD, I want to write some failing unit tests before I start refactoring. Any good way to do this? My first thought is just create a couple threads and make them all use the class in an unsafe w...

Testing things that should be the same both ways

For example the Equals method. a should equal b and b should equal a. Would you say it is OK to check this in one test case using two asserts like the following: [Test] public void Equals_TwoEqualObjects_ReturnsTrue() { var a = new Something(); var b = new Something(); Assert.That(a.Equals(b), Is.True); Assert.That(b.Eq...

Java/J2EE standard practices and design choices

I have a couple of design/architectural questions that always come up in our shop. I said "our", as opposed to "me" personally. Some of the decisions were made and made when J2EE was first introduced so there are some bad design choices and some good. In a web environment, how do you work with filters. When should you use J2EE filte...

instantiating spring bean outside the container (for testing)

I have following in my applicaionContext.xml <bean id="IbatisDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@123.210.85.56:1522:ORCL"/> <property name="username" value="mydb"/> ...

Unit Tests in VS2008 force rebuild of all dependencies

Why, when I go through my unit tests in VS2008 - either using run or debug - does VS insist on rebuilding all the dependencies of the test project i.e. the projects that I'm testing in the unit tests? Sometimes they haven't changed - I've just amended some of the unit tests. Or perhaps I've modified one of the assemblies - yet it insist...

"Can't call method "dir_path" on an undefined value" when running Mason component on the command line

Greetings, I'm trying to develop some tests for Mason components which requires running them on the command line instead of the web server. When I try this, I get an error: perl -MHTML::Mason::Request -MHTML::Mason::Interp -I./lib \ -e '$int = HTML::Mason::Interp->new( data_dir => "/home/friedo/cache", comp_root => "/home/friedo/comps"...