unit-testing

Getting groovy, maven, and eclipse to play nice together?

So we have some unit tests written in groovy. We have the Groovy Eclipse plugin going, we have gmaven going, but the problem is that the maven eclipse plugin doesn't automatically add the src/test/groovy directory as a source directory. So, I enlisted the build-helper plugin to add a source directory, but then the problem becomes the sou...

Problem with python packages and tests

I have a directory struture like that: project | __init__.py | project.py | src/ | __init__.py | class_one.py | class_two.py | test/ | __init__.py | test_class_one.py Which project.py just instantiate ClassOne and run it. My problem is in the tests, I don't know how to import src classes. I've tried importing the...

How do i add a project for Unit tests in c# in vs2010 ?

I must be missing something, i have VS2010 Premium. Under Templates, Test Projects -> Test Documents, there is only 1 thing listed called 'Test Project' If i select his, it adds the Unit testing framework to the solution, but the project it adds is for VB.NET --- does c# not have this option? thanks :-) ...

How to unit test wxPython?

I've heard of unit testing, and written some tests myself just as tests but never used any testing frameworks. Now I'm writing a wxPython GUI for some in-house data analysis/visualisation libraries. I've read some of the obvious Google results, like http://wiki.wxpython.org/Unit%20Testing%20with%20wxPython and its link http://pywinauto.o...

More bugs in unit tests than in production code

I just started a new project, and now with ASP.NET MVC being designed in an extremely composable way, I figured it might be a good time to start with unit testing. Most of my code is fresh, and I'm writing the tests before I'm writing the actual production code. My frustration, though, is that I spend a lot more time fixing mistakes in ...

Creating a test case for a buffer overflow error (C/c++)

Hello, How do you create a unit test case in c for a buffer overflow that does not cause a memory error such as a segfault? I.e. Given a simple buffer overflow, such as int function () { int exampleArray[10]; exampleArray[10] = 5; return 0; } How do you create a unit test for this code? There is clearly an error, we are ...

When to use the TestProperty-Attribute in the Silverlight Unit Test Framework?

The other Attributes (aka. TestMethod, ExpectedException, etc.) i know where and when to use, but i don´t know what i can do with the TestProperty-Attribute. Why should i use it and when? Whats the reason for this attribute? I found no useful documentation on the Internet, that explains the TestProperty-Attribute. And intellisense doe...

How to write multi-threaded unit tests?

I'd like to know if there are some unit testing frameworks which are capable of writing multi-threaded tests easily? I would imagine something like: invoke a special test method by n threads at the same time for m times. After all test threads finished, an assertion method where some constraints should be validated would be invoked. My...

Loading datasets in consecutive tests fails with "closed session"

Hi all, I have 2 test classes, both annotated with the unitils annotation @DataSet("/dbunit-dataset.xml") The target database is an HSQLDB, which is initiated in an abstract superclass method annotated with the testng annotation: @BeforeClass When the testrunner (Maven Surefire) arrives at the 2nd test, the database is correctly i...

what to unit test after refactoring common code into separate class

Let's say I've got two classes, each fully tested. There's duplication though, so I refactor the common code into a new class. Should I unit test that new class? If so, how? Here's the options I can see: don't unit test the new class (it's already fully tested by the original tests) copy+paste the original tests to the new test class ...

How do I unit test this class?

Suppose I need to add unit tests for the following class from legacy code (that has no unit test for now). It is just a simple map or dictionary. function Map(...) { ... } Map.prototype.put = function (key, value) { // associate the value with the key in this map } Map.prototype.get = function (key) { // return the value to whic...

Unabled to get multiple Test Methoeds to appear in VS2008 Test Results Window

I'm working on my first VS2008 unit test project and have run into problem. I'm using a wizard created test project and my unit test class (simplified) is - namespace FileWrapperUnitTest { [TestClass] public class UnitTest1 { public UnitTest1() { // initialization stuff } public TestContext TestContext { get; s...

How to test the accelerometer for Windows Phone 7?

I'm wondering what is the best way to test the accelerometer? There doesn't seem to be any simulation for movement on the emulator, and mocking seems like it would be difficult. Should I just do a best guess and wait until the real devices come out or is there another approach to consider? ...

Why is this instance variable nil when accessed in a different unit test?

require 'rubygems' require 'test/unit' class Thing attr_accessor :foo def set_stuff @foo = 'bar' end end class ThingTest < Test::Unit::TestCase def setup @thing = Thing.new end def test_set_stuff @thing.set_stuff assert 'bar' == @thing.foo end def test_foo_in_other_test puts @thing.foo assert ...

Moq: how to verify a function that takes in a object created within a method

Hi all: I have the following method; public class MyClass { public Repository UserRepository { get; set; } public void CreateUser(Message someMsg) { if (someMsg.CanCreate) { var obj = new object(); UserRepository.Save(obj) } } } In my test case, I used Moq to mock out the Obj...

New to unit testing, how to write great tests ?

I'm fairly new to the unit testing world, and I just decided to add test coverage for my existing app this week. This is a huge task, mostly because of the number of classes to test but also because writing tests is all new to me. I've already written tests for a bunch of classes, but now I'm wondering if I'm doing it right. When I'...

Moq controller tests with repeated setup

I am getting started on the Moq framework and absolutely love it. I am writing some controller tests that have several services and interfaces to Arrange my controller for the test. I'd love to modularize it a bit more, and thought this would be a trivial task, but it turns out to be a bit trickier than I thought. Here is one simple un...

Is there a way to execute initializer code before each test in Visual Studio Unit Testing (MSTest) for all tests in a project?

Hi everyone, I have a Unit Test project with 20+ .cs files. I want to run some setup code before each individual test. Kinda like how the [TestInitialize] attribute works. However, I'd need to put that attribute on all 20+ of my .cs files. Is there a way to centralize the initializing code in one place for every test in my entire pr...

Unit Testing in XCode

Hi, I am trying to test some model classes that I've written with SenTest in XCode. I have dragged the model header and implementation files into the Compile Sources group within my LogicTests target, and my tests pass. The problem though is that I'm getting a ton of compiler warnings about no rule to process file such as: warning: n...

How unit testing is better in ASP.NET MVC than Web Forms?

I have just started to learn ASP.NET MVC. When comparing ASP.NET MVC with Web Forms one of the main advantage of MVC is always told to be better support of Unit Testing. Can I got a good explanation of how it has better support? Edit : If possible please provide example in both. ...