unit-testing

Can Visual Studio Unit Tests be "Run as Admin" on Vista?

We have some unit tests which work with performance counters (specifically creating new categories) and on XP/2003 they work fine but on Vista/7 they fail with a SecurityException ("Requested registry access is not allowed"). I tried checking the "Run as administrator" box on the properties for VSTestHost.exe, but that causes all tests ...

Unit Testing a 'SetDefaults()' method

I am in the process of learning to unit test. I have a 'domain object' that doesn't do much apart from hold state (i.e. 'Employee' without any business logic). It has a method SetDefaults() which just fills its state with reasonable values. A simple method. But when I go to unit test this method all I can think of is to run the metho...

Unittesting IList with CollectionAssert

The mstest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparantly a list is not a collection.. Are there ways to make my IList an ICollection? ...

Cleaning up data after a selenium test

I'm setting up some Selenium tests for an internal web app and looking for advice on a testing 'best practice'. One of the tests is going to add some data via the UI that cannot be removed via the UI (e.g., you can add a record via the web app, but removing requires contacting someone internally to remove it at the database level). How d...

What is the "right" way to test the output of Java methods?

In Python, I often have tests which look something like this: tests = [ (2, 4), (3, 9), (10, 100), ] for (input, expected_output) in tests: assert f(input) == expected_output What is the "right" way to write tests like this (where a set of test cases is specified, then a loop runs each of them) in Java with JUnit? Tha...

Code coverage in unit testing

This is about .NET libraries (DLLs). What are the options for measuring code that is covered by unit test cases? Is it actually worth the efforts (measuring the code coverage)? I wonder it might be too easy to cover 70% of code and almost impossible to go beyond 90%. [EDIT] Another interesting question (put up by "E Rolnicki") is: What...

Can automated testing completely replace the need for manual testing?

There's no denying the benefits of automated testing. Automation increases test reliability and speed. With technologies like xUnit and Fit is it possible to forgo manual testing altogether? The one weakness of these frameworks seems to be the UI but there are free and commercial UI automation testing suites as well. Is manual testing ...

Needed: File system interfaces and implementation in .NET

I write unit tests to my code, using Moq as a mocking framework. My code includes calls to the file system, using direct calls to System.IO classes. For instance, File.Exists(...) etc. I'd like to change that code to be more testable, so I should have an interface, say IFile, with a relevant method, say Exists(string path). I know I can ...

Get the VK int from an arbitrary char in java

How do you get the VK code from a char that is a letter? It seems like you should be able to do something like javax.swing.KeyStroke.getKeyStroke('c').getKeyCode(), but that doesn't work (the result is zero). Everyone knows how to get the key code if you already have a KeyEvent, but what if you just want to turn chars into VK ints? I'...

Python: Running all unit tests inside a package

I'm trying to hack my through an open source python project (namely: jinja2), When I say "I'm hacking my way through", I mean I don't really know what I'm doing, so I want to run unittests whenever I change something to make sure I'm not breaking something major! There's a package full of unit tests (if you want to have a look, it's h...

Switching test::unit with rspec under rails

Kinda odd question here: when you go with rpsec instead of test::unit on rails, what do you do with the test dir? Keep it (for any compatibility issues maybe?) or remove it? ...

What is your favorite unit testing pass/fail slang?

I want to talk like I'm in the military of NUnit, but don't like the term "Green grass" as used by Rob Conery. Do you know any others? ...

How to do "performance-based" (benchmark) unit testing in Python

Let's say that I've got my code base to as high a degree of unit test coverage as makes sense. (Beyond a certain point, increasing coverage doesn't have a good ROI.) Next I want to test performance. To benchmark code to make sure that new commits aren't slowing things down needlessly. I was very intrigued by Safari's zero tolerance poli...

Automated Unit testing for Javascript integrated with CruiseControl, nUnit, nAnt and ASP.net MVC

I work for a team of ASP.net MVC and they are using Cruisecontrol, nUnit and nAnt for the automated testing and build. I am new to the group and i handle the Javascript layer and i am looking for ways to incorporate my work with my teams workflow. Are there any possoble way to do this? Thanks ...

How can you use utility functions with UnitTest++

I'm using UnitTest++ for unit testing C++ code. In my tests, there's a group of tests I repeat several times. What I'd like is for a utility function to perform these tests. In short, I'd like to take this: TEST( foo ) { Foo one; Foo two; // init one & two // lots of CHECK_CLOSE(one.bar, two.bar, 1e-5); in repeating cy...

How do you do Unit Testing With an App that Uses an ORM?

I've looked through the various questions on unit testing but can't find one that specifically answers this question. I've got several PHP classes that contain functions that look like this: static function _setSuspended($Suspended, $UserID) { try { $con = Propel::getConnection(); $c1 = new Crit...

ASP.NET MVC: Unit testing controllers that use UrlHelper

Hello, One of my controllers actions, one that is being called in an Ajax request, is returning an URL to the client side so it can do a redirection. I'm using Url.RouteUrl(..) and during my unit tests this fails since the Controller.Url parameter is not pre-filled. I tried alot of things, among others attempting to stub UrlHelper (whi...

Test data directory with jUnit

I'm writing some jUnit tests that depend on data files. Where should those data files go? And how would I (in the jUnit tests) get the location of that directory? In Python, I would use something similar to: datadir = os.dirname(__file__) + "/data/" ...

How to unit test server controls on postback?

I am trying to create my own EasyBinderDropDown that currently looks like this: public class EasyBinderDropDown : DropDownList, ICanBindToObjectsKeyValuePair { public void BindToProperties<TYPE_TO_BIND_TO>(IEnumerable<TYPE_TO_BIND_TO> bindableEnumerable, Expression<Func<TYPE_TO_BIND_TO, object>> textPro...

JUnit assertion extensions

I'm often creating custom assertion methods for my JUnit tests. eg: public void assertArrays(String[] actual, String[] expected) I was wondering if there were any decent third party libraries that can provide a wider range of assertions than what comes by default in JUnit. Am using JUnit 4. ...