unit-testing

Is it possible to test a JPA/EJB QL statement with regex?

I'm not an expert on regular expressions so I thought I'd throw this question out. I'm thinking regular expressions can help make my tests more robust (testing generated EJB QL statements for correct generation). For example: select u.firstName, u.lastName from Users u where u.age > 50 What regex do I use to split it into the followin...

Unit testing the DAL - please critique

Hi, I've gotton to the point in my simple project where I'm ready to unit test the DAL. I basically have a class called FooDataAccess with several very simple functions, lets say 3 of them like this: int InsertFoo(string fooName) void UpdateFoo(int fooID, string fooName) void InsertFoosDepedency(int fooID, string someValue) What I d...

Creating testable code

I have a file - in a large legacy codebase - containing methods that access databases. No classes are used, just a header file with the method declarations, and the source file with the implementation. I want to override these methods to eliminate the DB access during unit testing. I thought of the following options: Make file into c...

How to unit test a query that returns articles by a date range?

Say I have a articles table, and I want to write a test for the method that returns all articles that are about to expire. How would I go about writing a unit test for this? If I mock the collection of articles that the method returns, how is that a unit test? I mean I want to make sure it returns the correct data range of articles? ...

Unit Tests: DRY vs. Predictability

Should we aim for DRY, in the sense that changes to the functionality affect as little code as possible, our predictability, in the sense that operation of the code is trivial, when writing unit tests? Basically I'm asking about the trade-off between creating helper methods that are very general and that can be used by multiple unit test...

Mocking java object for unit test

Hi, I am looking for a good unit test framework that I can use to mock private methods that can run under JDK 1.4.2. Cheers, ...

How to test cryptography methods

I recently have a problem with a crypto library which produces bad md5 output. Instead of 32 digits it returns 30. As we don't use unit test, this problem was quite a headache to solve... because we assumed that md5 string was correct and look for bugs in other places. That make me realize of the real value of unit tests (unit test fir...

Testing file based persistence

we have code that persists a file and I would like to check the content of the file during testing. I though that such scenario will be best implemented if I abstract the file persistence operation to the following interface: public interface IFilePersist { void Save(XXX, FileLocation); } In unit testing I will inject the mock that...

Outputting (puts, print) in Rails Unit Tests

How come commands like puts and print don't show up in the console when running ActiveSupport::TestCase tests? Makes it very hard to debug if I can't outputs some inspections in a couple of methods. Thanks! ...

How to run a single shoulda context test in ruby Test::Unit framework

I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test": ruby functional/user_controller_test.rb -n delete_user_test Now when I'm using the shoulda plugin with Test::Unit I try to use the same technique as follows: ... context "Deleting a User" do should "remove user ...

Bad inputs for unit testing on a text parser

I would like to write the unit test for a text parser class but I am not sure about the Bad Inputs I need to give to the test method in order to be sure it work in all possible cases. The method uses some regular expression plus string manipulation, but if I understood well the Unit Testing approach I don't have to concentrate on the me...

Is Guice needed in unit test?

I was told the Guice is aim to produce testable code, and not needed in the unit test. But how can I test a Singleton(@Singleton) without use Guice? ...

Unit Test - Check a method call with an object that doesn't override equals

Hi All, This is a general question on how to unit-test a Java Class using mock objects. I can summarize my problem with this example. Let's say I've an Interface called MyInterface.java and a "TwoString" Object that doesn't override equals() "TwoString.java" private String string1; private String string2; public TwoString(...

Asp.Net Mvc Unittesting a controller action

I have the following action that Im trying to unit test: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Default(ProductsViewModel model) { var locationId = model.LocationId; var locationText = model.LocationText; return locationId > 0 ? Summary(locationId, locationText, 1, "Date", true) : View(); ...

Unit Testing a Windows Scheduled Task Console App

Hi all, I am in the process of taking over a legacy system that contains a Console App project, which is run as a Scheduled Task on our production servers. It mainly produces daily and weekly reports, does some database maintenance, etc. The "main" of the console app handles inputting the command line arguments and determining which o...

Create Pex test to test a DLL and hardware controlled by that DLL?

Create Pex test to test a DLL and hardware controlled by that DLL? I have some hardware that has an api in that is controlled by a DLL. I have written some unit tests in nunit that will call the appropriate pieces of the API and do a test. For instance I might have a "get data test", that has an 1. open, 2. read on one side and 3. send...

Unit Testing HtmlHelper that Needs to Access Data Layer

I am trying to create a unit test for an HtmlHelper that accesses my data layer to get a string. I have looked at a lot of posts around this and I am probably missing something. The problem that I am having is how do I mock the access to my data layer? I usually do my dependency ijection through the constructor, but I cannot here beca...

invalid project file format Nunit

NUnit 2.5.0 C# Class Library .NET 3.5 I have a strange error that just recently started to occur. When trying to open a c# class library project in Nunit it immediately throws an exception: System.NullReferenceException... at NUnit.Util.VSProject.LoadMSBuildProject(String projectDirectory, XmlDocument doc) at NUnit.Util....

Unit Testing of framework 1.1 project with Visual Studio 2008?

Is it possible to write and run with Visual Studio 2008 some unit test and target a project written with framework 1.1? ...

Reference a .Net2.0 project from a .Net3.5 solution without upgrading project file [csproj]

Hello StackOverflow. I have an interesting problem. I am developing for a .Net2.0 solution. I have finished my development and checked my source in [er, to a local Clearcase stream - don't ask, this just means I'm done dev]. This source is, and must remain .Net2.0 Vs2005 compliant. Unit testing is somewhat more lax. I would like to tak...