unit-testing

Django unit testing - Why can't I just run ./tests.py on myApp?

So I'm very familiar with manage.py test myapp. But I can't figure out how to make my tests.py work as an stand-alone executable. You may be wondering why I would want to do this.. Well I'm working (now) in Eclipse and I can't seem to figure out how to set up the tool to simply run this command. Regardless it would be very nice to sim...

LINQ to SQL testing

Hi I'm using Linq to sql to access an SQL Server. I try to write all my database queries in a partial class so they can be accessed directly from the DataContext. Now I would like to test the Data Context but I can't figure out the best way och doing that. Bascially I need to test 3 things: 1. The queries return the correct data (no...

How can I do to profile ruby Unit tests execution?

I'd like to know how much took to run the 10 most time consuming tests.. like I can do with rspec, any suggestion? ...

RhinoMocks - Stub a Method That Returns a Parameter

I am using RhinoMocks, I need to stub a method, and always have it return the third parameter, regardless of what is passed in: _service.Stub(x => x.Method(parm1, parm2, parm3)).Return(parm3); Obviously, it ain't that easy. I don't always know what the parms are going to be, but I know I always want to return the 3rd one. ...

how to unit test an email rule

I download an employee's email into a table, I then take that collection of emails I just downloaded and run a bunch of rules on them. e.g. if email from [email protected], route the email to folder1. How could I write a unit test for this process? Would I have to create a dummy collection of emails, and then right a rule for each one? I...

GH-Unit and Objective C++

I have an iPhone project that uses GHUnit to conduct unit testing. Recently, I've needed to implement complex numbers and overload some operators to ease the calculation of FFTs. The goal here was to create a clean way to perform an FFT without the overhead of all the possible functionality that libraries like FFTW uses, and in this se...

Python Unit Tests - Am I using SetUp wrong?

What am I doing wrong here? import unittest class Test_1(unittest.TestCase): def SetUp(self): self.data = [] def test_data(self): self.assertEqual(len(self.data),0) if __name__=='__main__': unittest.main() When I run it, it says: Traceback (most recent call last): File "C:...\break_unit_test.py", ...

How should unit tests be documented?

I'm trying to improve the number and quality of tests in my Python projects. One of the the difficulties I've encountered as the number of tests increase is knowing what each test does and how it's supposed to help spot problems. I know that part of keeping track of tests is better unit test names (which has been addressed elsewhere), bu...

Is this file lock issue due to me copying the DB file for every MSTest test? (using DeploymentItem annotation)

Hi, BACKGROUND: I've running unit tests in VS2008 using MSTest. My project has a SqlLite database. I have found that I needed to arrange for the default database file to be copied to the MSTest area for the test to be able to find it. I am using the following annotation about the test code to arrange this: [DeploymentItem("dat...

rspec testing views with internationalization ?

Hello, I want to make sure I have the right meta desc/keyword and title text in my view so I want to create rspec views tests for that. Now the real challange here is how to make it work across multiple languages. The way I've done it is: it "should have the right page title" do title = "some nice title here" response.should have_...

How do I mock an IEnumerable<T> so that I can test a method that receives it

I have a method that I want to test which expects an IEnumerable<T> as a parameter. I'm currently mocking the contents of the IEnumerable<T> as follows (Using Moq): var mockParent = new Mock<ICsvTreeGridExportable>(); var mockChild = new Mock<ICsvTreeGridExportable>(); How do it put these mocked objects inside an IEnumerable<T> so ...

unit test a method that creates an object

I'm trying to get my head round Unit Testing and there's one more piece of the jigsaw I need to find. What I'm trying to do is write tests for the following code. In this case, I've got a really simple Front Controller (written in PHP). class frontController { public function routeRequest($oRequest) { $sClassname = $oReques...

Error: "Exception has been thrown by the target of an invocation."

Hi all, I use VS 2008 professional, and use Unit tests. Sometimes, I get the error: Error: "Exception has been thrown by the target of an invocation." http://peitor.blogspot.com/2009/10/sometimes-it-works-sometimes-not.html What I did and didn’t help: Start up Visual Studio in safe mode (parameter /SafeMode ) Start up Visual Stud...

SpringJunit4ClassRunner -- can I change the lifetime of the injected resources?

By experiment, I find that SpringJunit4ClassRunner treats the context and its beans as 'class scope' in the JUnit sense of scope. It inititializes my beans once for the entire set of tests in the class. Is there any way to use this mechanism and get these things to be 'test scope'? In short, I wish that the context was being loaded as @...

What are the (dis)advantages of writing unit tests in a different language to the code?

Unit tests have different requirements than production code. For example, unit tests may not have to be as performant as the production code. Perhaps it sometimes makes sense to write your unit tests in a language that is better suited to writing unit tests? The specific example I have in mind is writing an application in C# but using I...

Run all unit test in Python directory

So I have a directory that contains my Python unit test. Each unit test module is of the form "test_*.py". I am attempting to make a file called "all_test.py" that will, you guessed it, run all files in aforementioned test form and return the result. I have tried two methods so far, both have failed, I will show the two methods, and hope...

Unit Tests for JPA/Persistence in General

How/would you test super-simple methods that are built on a persistence engine. I'm going to use JPA but any persistence mechanism I'm sure has its equivelents. For example... @Entity public class Category { @Id @GeneratedValue private long id; @NotNull @NotEmpty private String name; @NotNull @ManyToOne private ...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem is, with symfony you can test with the lime framework, which is great. But most of the code writes, deletes or do other things with the dat...

Unit testing real-time / concurrent software

The classical unit testing is basically just putting x in and expecting y out, and automating that process. So it's good for testing anything that doesn't involve time. But then, most of the nontrivial bugs I've come across have had something to do with timing. Threads corrupt each others' data, or cause deadlocks. Nondeterministic behav...

Where can I find good unit testing resources for EJB and J2EE?

Which online resources, tutorials or books can you recommended to get started with unit testing J2EE / EJB3 applications? So far I have found ejb3unit, Jakarta Cactus and the Maven Cargo plugin. It would be helpful if there are complete working examples, ready to run. Target containers are the open source products GlassFish, JBoss and ...