unit-testing

Is there a way to make WatiN click a link before the page finishes loading

We're using WatiN for testing our UI, but one page (which is unfortunately not under our teams control) takes forever to finish loading. Is there a way to get WatiN to click a link on the page before the page finishes rendering completely? ...

How to convince a project sponsor that all functions in your code should have unit tests

Non technical people in most cases do not see any value in writing unit tests. They just want to have basic code completed and do not spend money and time on such things like unit tests. Later, every day they just to ask to fix a one bug more. Projects are missing deadlines and they still don't see value in good automated tests. ...

The best way to validate XML in a unit test?

I have a class with a ToString method that produces XML. I want to unit test it to ensure it is producing valid xml. I have a DTD to validate the XML against. Should I include the DTD as a string within the unit test to avoid a dependency on it, or is there a smarter way to do this? ...

How do I allow assembly (unit testing one) to access internal properties of another assembly ?

I would like my Core assembly to not expose a certain class and I would still like to be able to test it. How can I do that ? ...

BNF grammar test case generation

Does anyone have any experience with a tool that generates test strings from a BNF grammar that could then be fed into a unit test? ...

How are people unit testing code that uses Linq to SQL

How are people unit testing code that uses Linq to SQL? ...

What factors could cause the following SqlException: A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 1 - I/O Error detected in read/write operation)

I've started seeing this message intermittently for a few of the unit tests in my application (there are over 1100 unit & system tests). I'm using the test runner in ReSharper 4.1. One other thing: my development machine is a VMWare virtual machine. ...

Is it possible to unit test a class that makes P/Invoke calls?

I want to wrap a piece of code that uses the Windows Impersonation API into a neat little helper class, and as usual, I'm looking for a way to go test-first. However, while WindowsIdentity is a managed class, the LogonUser call that is required to actually perform the logging in as another user is an unmanaged function in advapi32.dll. ...

How can you unit test a database in SQL Server?

What are some of the ways? What frameworks can you use? ...

Unit-testing servlets

I have a bunch of servlets running under the Tomcat servlet container. I would like to separate test code from production code, so I considered using a test framework. JUnit is nicely integrated into Eclipse, but I failed to make it run servlets using a running Tomcat server. Could you please recommend a unit testing framework that suppo...

Rhino Mocks - How can I test that at least one of a group of methods is called?

Say I have an interface IFoo which I am mocking. There are 3 methods on this interface. I need to test that the system under test calls at least one of the three methods. I don't care how many times, or with what arguments it does call, but the case where it ignores all the methods and does not touch the IFoo mock is the failure case. I...

What is the best style/syntax to use with Rhino Mocks?

Multiple approaches exist to write your unit tests when using Rhino Mocks: The Standard Syntax Record/Replay Syntax The Fluent Syntax What is the ideal and most frictionless way? ...

How do I know when to use state based testing versus mock testing?

Which scenarios, areas of an application/system, etc. are best suited for 'classic' state based testing versus using mock objects? ...

Why is a method call shown as not covered when the code within the method is covered with emma?

I am writing a unit test to check that a private method will close a stream. The unit test calls methodB and the variable something is null The unit test doesn't mock the class on test The private method is within a public method that I am calling. Using emma in eclipse (via the eclemma plugin) the method call is displayed as not bei...

Is it possible for SelectNodes on an XmlDocument to return null?

Is it possible for SelectNodes() called on an XmlDocument to return null? My predicament is that I am trying to reach 100% unit test code coverage; ReSharper tells me that I need to guard against a null return from the SelectNodes() method, but I can see no way that an XmlDocument can return null (and therefore, no way to test my guard ...

Unit testing MVC.net Redirection

How do I Unit Test a MVC redirection? public ActionResult Create(Product product) { _productTask.Save(product); return RedirectToAction("Success"); } public ActionResult Success() { return View(); } Is Ayende's approach still the best way to go, with preview 5: public static voi...

Best Way to Unit Test a Website With Multiple User Types with PHPUnit

I'm starting to learn how to use PHPUnit to test the website I'm working on. The problem I'm running into is that I have five different user types defined and I need to be able to test every class with the different types. I currently have a user class and I would like to pass this to each function but I can't figure out how to pass th...

How are Mocks meant to be used?

When I originally was introduced to Mocks I felt the primary purpose was to mock up objects that come from external sources of data. This way I did not have to maintain an automated unit testing test database, I could just fake it. But now I am starting to think of it differently. I am wondering if Mocks are more effective used to com...

Pex users: what are your Impressions of Pex and Automated Exploratory Testing in general?

Those of you who have used Pex, what do you think its advantages and disadvantages are of Pex as a tool? Also, what do you think are the advantages and disadvantages of "Automated Exploratory Testing" in general, as a supplement to TDD/Unit Testing? ...

When Testing your MVC-based UI, how much of the test setup do you make common?

I'm trying to test a simple WebForms (asp.net) based UI, and follow the MVP pattern to allow my UI to be more testable. As I follow the TDD methodology for backend algorithms, I find that there are some unit test refactorings that happen in the spirit of the DRY principle (Don't Repeat Yourself). As I try to apply this to the UI using ...