unit-testing

Maximum length for unit test classes?

I use JUnit and the standard practice of having a XXXTest class for each class I am testing. When writing some tests today I noticed that the test class was about to reach 10000 lines. Are there some best practices relating to the maximum length of a unit test class? Should I split my unit test class into multiple classes? ...

Unit testing controller actions with complex viewModels

Hi, I'm just getting going with ASP.NET MVC and I'm also new to unit testing :) So far, so good. I have a controller action that sets up an index view using a viewmodel. Testing the controller action is straight-forward as I can pass a fake service class in the controller's constructor, but my viewmodel is quite complex and fetches i...

How do you import main classes in test classes in Maven?

I have generated a new Scala project with Maven and it created a folder structure with a src/main/scala and a src/test/scala folder. I have some code in src/main/scala and wanted to write some tests, the problem is that I can't import the classes from src/main/scala. How do I do that? ...

When should you stop unit testing

I can often identify plenty of areas which are nicely encapsulated and easily unit tested, but I also find that a lot of code where unit testing doesn't really seem to work as well - typically data access and user interface. No matter what unit testing "techniques" I try I tend to find that in these places it's not only a lot of effort t...

How to start unit-test old and new code ?

I admit that I have almost none experience of unittesting. I did a try with DUnit a while ago but gave up because there was so many dependencies between classes in my application. It is a rather big (about 1.5 million source lines) Delphi application and we are a team that maintain it. The testing for now is done by one person that use ...

Is it possible and/or advisable to generate tests dynamically in rails?

One trick I have found very handy in rails application programming is that class_eval can be used to create methods on the fly. I'm starting to get into testing now and I wonder if a similar idea could be used to generate tests. For example, I have a before_filter to require a user to be logged in for all of the actions in a controller...

Unit tests that inherit from a type that uses generics

I have an interface with generics that is implemented by some classes. For each of these classes there is proxy class that implement the interface as well. Giving roughly this code: public interface ISomeInterface<T> { T SomeProperty { get; } T SomeAction(); } public interface IClassA : ISomeInterface<string> {...

How can I load a local resource synchronously in Flex 3?

I want to store some test data for a FlexUnit test in small XML files in my Flex project, and access them trivially for the flex test. How can I load these bits of data synchronously? HTTPService is the way I'd be loading them _a_synchronously, but adding event handlers to my test cases seems like a bit of overkill. ...

.NET Unit Testing - Best Practices for hiding test seams in release code

I'm looking for some advice for unit-testing in a manner that doesn't leave "test hooks" in place in production code. Let's say I have a static class (VB.NET Module) named MethodLogger who has a "void WriteEntry(string Message)" method that is intended to write the calling method and a message to a log file on disk. The actual target o...

Visual Studio 2008 Testing A Method?

Now this might be a dumb question, but I'm still new to using Visual Studio 2008 but I was wondering if there is a feature like this (I'm using webforms ASP.NET C#). I create a new method, highlight it in the editor and was wondering if there was a run/test method feature? Where it would exectute the method and prompt me via a UI for a...

How to generate javadoc for unit tests in netbeans

I'm using Netbeans (currently 6.7) and I really like how I can generate javadoc from my source code. However my tests also have documentation (valuable documentation!). Is there anyway I can generate javadocs (ideally for both at the same time). Thanks! ...

Why should I do UnitTest for my SQL, DAL and BLL if my App will only call BLL metods?

I've put up some tests using VisualStudio integrated test enviroment, they simultate what my web application would do by calling BLL methods (they only ones the UI layer should know and interact with)... So if their behaviour is correct - I get my tests passed - why should I write tests for lower layers such as DAL/Stored Procedures as ...

ASP.NET MVC - Testing Page to Model Binding

Hello, I have unit tests covering my model binders. I create a ModelBindingContext and populate the ValueProviderDictionary with my test values. I feel confident that once my controller gets the model, everything is covered with testing and the right things are happening. I also feel confident that if the BindingContext is correct my...

In Need of Refactoring in Order to Improve Testability

Hi, I'm testing a simple DAO layer with mockito but I found a problem, basically a hard to test interface and I was wondering if you could give me some insight... This is the method I want to test: public Person getById(UserId id) { final Person person = new PersonImpl(); gateway.executeQuery(GET_SQL + id.getUserId(), new Resu...

Visual Studio Unit Test - DELETE permission denied

I am running a Sql statement similar to the following inside of a cleanup method of a unit test in Visual Studio 2008: DELETE FROM MyTable WHERE EmployeeID = @EmployeeID AND UserID = @UserID ... @EmployeeID & @UserID are assigned appropriate values via parameters in an SqlCommand and ExecuteScalar() is called to execute the statement. ...

Why does Visual Studio (2008) create all these *.vsmdi files

Why does Visual Studio (2008) unit testing create all these *.vsmdi files? Can it be turned off? ...

How to test anonymous classes?

I believe you must be familiar with this idiom, which is sort of java's excuse for closures //In the "Resource Manager" class public void process(Command cmd){ //Initialize ExpensiveResource resource = new ExpensiveResource(); //Use cmd.execute(resource); //Release / Close resource.close(); } //In the Client class... manage...

Does it make any sense testing this? (Repository pattern)

Getting started with TDD and the repository pattern, I'm wondering if it makes any sense testing this... Using the repository pattern, I have this interface: public interface ICustomerRepository { IList<Customer> List(); Customer Get(int id); } I have like 50 different entities, so 50 different repository interfaces/implement...

DataContext crashes when unit testing

I am using Linq to SQL in my project. I have a part of the code that calls DataContext db = new DataContext() This works as expected when running the website however when calling this from within my unit test I get an error object not set to an instance... Do you know why this is? I know I should Mock the data context for testing bu...

New to TDD: Are there sample applications with tests to show how to do TDD?

I really want to get into TDD development but I have no point of reference where to start. I think that looking at code and seeing how they write tests and make classes testable that it'll be easier for me to digest and start using myself. Is anyone aware of any sample or small open source C# applications that include unit tests? ...