unit-testing

MissingPropertyException while running unit tests for Grails service class

I am writing unit test cases for my Service Class. Below is my code in controller: TuneController def list = { } def listData= { playerId="6600AE" def tuneInstanceList = new ArrayList<Tune>() tuneInstanceList = tuneService.calculateId(String playerId) def editResult = [total: tuneInstanceList.size(), items: tuneI...

How do I Raise an Event using Rhino Mocks that has a ref bool parameter

I am trying to write a test that covers my error handling in a particular class. This class is listening for an Error event with the following signature: OnError(int ErrorNumber, string ErrorText, ref bool retry) The problem is with the ref bool variable at the end. I am using Rhino Mocks to create a mock interface for testing and w...

Retrieve count of SelectList items?

Problem: I can't access the count of items in a SelectList I have an HtmlHelper method that returns a SelectList: public static SelectList FilterSelectList(this HtmlHelper helper, List<Stuff> eList, string dept) { List<Stuff> returnList = new List<Stuff>(); //Do Stuff return new SelectList(returnList, "ID", "Name"); } I then...

Wicked JUnit Date trick - How would you do this in C#?

Gojko Adzic posted today on his blog about Steve Freeman's unit-testing trick, which helped make it crystal clear why the date comparison in the unit test failed. Here is the blog post describing the trick - it is not long. The key part of the trick is this method (in Java), which overrides ToString() on a particular instance of the Da...

Is it safe to always create a new HttpContextWrapper?

I'm trying to make an existing ASP.NET web forms app more unit testable by using some of the ASP.NET MVC objects, specifically HttpContextWrapper. I've seen examples of its usage and they always create a new object. I disassembled the source with Reflector and see all it does is store the passed HttpContext. But I was curious as to wheth...

Unit-testing framework for MATLAB

What are the unit-testing frameworks for MATLAB out there, and how do they compare? How should I choose one for our project? What are their pros and cons? ...

better jUnit test coverage needed

Good evening everyone Suppose your code has the following statement: if (string ends with char 'y') { if ((char before last is not 'e') || (char before last is not 'a')) { return (something awesome); } } So that's simple enough i thought ... Test1: input = "xy" (last char is y, char before last is not e or a) Result - part...

How To Properly Unit-Test CRUD Operations on a Repository?

Hi Guys, Realize this may sound like a broad question - so let me clarify. I have a Repository exposed via an interface, with two concrete implementations - a MockRepository and a EntityFrameworkRepository. Now, i have a Unit-Test project for which all tests can be run against either repository, via flicking over a line in [TestInitial...

Microsoft testing framework measure time

Is there any build in features I may measure code/methods execution time using visual studio 2010 in Microsoft testing framework ? Or only Stopwatch may help? ...

Execute Unit Tests using MsBuild command line

I use scripting for this: "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe" get $/DmlOnDemmand /recursive /force /noprompt And I build solution .sln call %msBuildDir%\msbuild %solutionName% /t:Rebuild /p:Configuration=%buildType% Now, I would like execute all Unit Tests and check all is OK. How can I execute unit t...

Unit Testing - Challenges with Dynamic / Interrelated Repositories

I have a handful of controllers and each controller has a test class with unit tests. Each unit test calls a single action and verifies that the action handles a given scenario. The test class has a setup routine that instantiates a number of fake repositories and other fake objects. The fake repositories have static collections that ...

How to organize in folders the UnitTests when the source code is in many folders?

THe source code of my the legacy application I am maintaining is in many folders and subfolders. I am starting creating unittests as a base for refactoring. Do you suggest I put all tests in a single place or for every folder of code i create a subfolder called \FolderNameTests ? Or do you have other suggestions? ...

How to compare vectors with Boost.Test?

I am using Boost Test to unit test some C++ code. I have a vector of values that I need to compare with expected results, but I don't want to manually check the values in a loop: BOOST_REQUIRE_EQUAL(values.size(), expected.size()); for( int i = 0; i < size; ++i ) { BOOST_CHECK_EQUAL(values[i], expected[i]); } The main problem is...

Are fakes better than Mocks?

I stumbled upon this open source project Fake It Easy, and I have to admit, it looks very interesting, however I have my doubts, what are the difference between FIE fakes and say Moq Mocks? Is any one better for particular uses? EDIT: What is it about this new framework that would make it better than say Moq? ...

How to test a custom Zend_Form with PHPUnit?

Does anyone have an example of how to test a custom Zend_Form that extend from that class with PHPUnit?? I may need to test the construct and the init... where i'm adding elements to the My_Custom_Zend_Form. ...

rails 3 test case error.on(:field) Vs. errors[:field]

I am working on the Rails 3 Test cases . While writing case i got Deprecation error like DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead. Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is returned when there are no errors on the specified attribute...

Does this unit test have to be in the same package as the controller it tests?

According to this example, it goes in the same package as the controller it tests. Why is that necesssary? I think it would be tidier to have all of my unit tests in a testing package - would there be a problem with doing so? package com.example.web.controllers; ...imports... @RunWith(SpringJUnit4ClassRunner.class) @ContextConfigur...

ASP.NET MVC - PasswordLength in a built-in unit test

Why does the last assert in this built-in unit test in the ASP.NET MVC 2 project pass? //File: AccountControllerTest.cs [TestMethod] public void ChangePassword_Get_ReturnsView() { // Arrange AccountController controller = GetAccountController(); // Act ActionResult result = controller.Change...

How would i unit test database logic?

Hi there. I am still having a issue getting over a small issue when it comes to TDD. I need a method that will get a certain record set of filtered data from the data layer (linq2SQL). Please note that i am using the linq generated classes from that are generated from the DBML. Now the problem is that i want to write a test for this. d...

How can I have a test unit in the same source file?

This question is Ruby related. Suppose I want to have the test unit for my class in the same file as it's definition. Is it possible to do so? For example, if I'd pass a "--test" argument when I run the file, I'd want it to run the test unit. Otherwise, execute normally. Imagine a file like this: require "test/unit" class MyClass en...