unit-testing

Using inheritance in MSTest

I am setting up some MSTest based unit tests. To make my life easier I want to use a base class that handles the generic setup and taredown all of my tests require. My base class looks like this: [TestClass] public class DBTestBase { public TestContext TestContext { get; set; } [ClassInitialize()] public static void MyCla...

Using fixtures with factory_girl

When building the following factory: Factory.define :user do |f| f.sequence(:name) { |n| "foo#{n}" } f.resume_type_id { ResumeType.first.id } end ResumeType.first returns nil and I get an error. ResumeType records are loaded via fixtures. I checked using the console and the entries are there, the table is not empty. I've found ...

Difficulty to start up with basic unit test (Sample from my book -- SportsStore)

Hello, I'm really new in TDD and, actually, I'm trying to follow the sample from my book (SportsStore -- Pro ASP.NET MVC Framework/Steve Sanderson/APRESS). I'm on pages 103-105. Although there are more on this, as new to all of this, I'm concerned with the following statements. ProductsController controller = new ProductsController(re...

Robust unit-testing of HTML in PHP

I'm adding unit-tests to an older PHP codebase at work. I will be testing and then rewriting a lot of HTML generation code and currently I'm just testing if the generated strings are identical to the expected string, like so: (using PHPUnit) public function testConntype_select() { $this->assertEquals( '<select><option value=...

Programming interview : quick ways to ensure that program is correct

Hi, I faced a telephonic interview recently and I was asked to write a program. The program is non-trivial to understand, but I am asked to write the program. I wrote the program and interviewer showed me bugs on some corner cases. I wish, I could have found the corner cases earlier. what does everyone do in this case. Thanks Bala ...

How to exclude file from PHPUnit test suite in xml config?

I have following, very simple, XML config for PHPUnit: <phpunit bootstrap="/_tests/TestAutoload.php"> <testsuites> <testsuite name="Unit Tests"> <directory suffix=".php">_tests</directory> </testsuite> </testsuites> </phpunit> How to exclude certain file in this directory from test suite? I tried <e...

Unit testing with Mocks when SUT is leveraging Task Parallel Libaray

I am trying to unit test / verify that a method is being called on a dependency, by the system under test (SUT). The depenedency is IFoo. The dependent class is IBar. IBar is implemented as Bar. Bar will call Start() on IFoo in a new (System.Threading.Tasks.)Task, when Start() is called on Bar instance. Unit Test (Moq): [Test] ...

how do i implement / build / create an 'in memory database' for my unit test

Hi all, i've started unit testing a while ago and as turned out i did more regression testing than unit testing because i also included my database layer thus going to the database verytime. So, implemented Unity to inject a fake database layer, but i of course want to store some data, and the main opinion was: "create an in-memory dat...

How to migrate Cppunit tests into GoogleTest ?

I have a bunch of module tests written in CPPunit with some mocks created by hand. I am looking for a way to migrate them to GoogleTest as smoothly as possible. Have you tried such an operation? What was the effort needed? ...

Error when running a GWTTestCase using maven gwt plugin

I've created a test which extends GWTTestCase but I'm getting this error: mvn integration-test gwt:test ... Running com.myproject.test.ui.GwtTestMyFirstTestCase Translatable source found in... [WARN] No source path entries; expect subsequent failures [ERROR] Unable to find type 'java.lang.Object' [ERROR] Hint: Che...

How to unit test for exception in threads

I need to unit test that an exception in raised in code like: def test assert_raise Timeout::Error do Thread.new { raise Timeout::Error } end end How to get this working? ...

how can a test script inform R CMD check that it should emit a NOTE?

I'm writing a R library together with other developers. we are using RUnit for unit testing. our process for describing new functionality: we define new unit tests, initially marked as DEACTIVATED; one block of tests at a time we activate them and implement the function described by the tests. almost all the time we have a small amou...

Unit test complex classes with many private methods

Hi, I've got a class with one public method and many private methods which are run depending on what parameter are passed to the public method so my code looks something like: public class SomeComplexClass { IRepository _repository; public SomeComplexClass() this(new Repository()) { } public SomeComplexClas...

Testing Python Decorators?

I'm writing some unit tests for a Django project, and I was wondering if its possible (or necessary?) to test some of the decorators that I wrote for it. Here is an example of a decorator that I wrote: class login_required(object): def __init__(self, f): self.f = f def __call__(self, *args): request = args[0...

Is there an RUnit checkException for warning()?

checkException will validate if meeting a stop() call, but not a warning() call. Is there a workaround or hack to check for warnings? (and make them silent during testing) thanks ...

Is the test suite setup method executed once for each test, or only once for all?

I know the answer may differ for each test framework. But for the ones you know, what should happen? ...

In few words, what can be said about Mocking process in TDD

I'd like to brush my brain to avoid confusions. In few words, what can be said about Mocking process in TDD What's the GREAT idea behind MOCKING? Mocking frameworks are meant to be used only to avoid accessing DB during tests or they can be used for something else? For new comers (like me), are all the frameworks equal or I need to ch...

Best testing framework?

Is JUnit the best unit testing framwork? Which framework is best for new java projects? ...

Is TDD broken in Python?

Hi! Assume we have a class UserService with attribute current_user. Suppose it is used in AppService class. We have AppService covered with tests. In test setup we stub out current_user with some mock value: UserService.current_user = 'TestUser' Assume we decide to rename current_user to active_user. We rename it in UserService but ...

How would you make a blog with a TDD approach?

I'm considering remaking my blog(currently in PHP, but <100 lines of non-layout code) in Ruby on Rails just for the fun of it. I want to make another project in Rails, but I should learn Rails(more than hello world) before I go to try to create a full project. Another thing I want to do while remaking my blog is to at least figure out ...