Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:31:28+00:00 2026-05-24T05:31:28+00:00

I used test-driven-development followed by some re-factoring and ended up with a set of

  • 0

I used test-driven-development followed by some re-factoring and ended up with a set of classes using composition to progressively increase type-specificity. For example:

  • EventDispatcher -> TypedEventDispatcher -> FooEventDispatcher
  • EventDispatcher -> TypedEventDispatcher -> BarEventDispatcher

So EventDispatcher dispatches generic events (String, Number, Object), TypedEventDispatcher only dispatches events based on objects, and FooEventDispatcher only dispatches Foo events, BarEventDispatcher dispatches Bar events and so on.

The tests for all classes have identical behaviour, the only difference is the object type which is tested against. I have found that when I want to add a new event type I end up with the same test code as for the other classes.

This amount of duplication is obviously wrong. The resulting tests are quite fragile, as when I add a new feature to TypedEventDispatcher, I need to add the same tests to any objects which use it.

In Java, .NET, or Haxe I would be to create a generic type and test against that, however I am using ActionScript which does not support generics which is why I need a new class for each type to maintain type-safety.

As far as I can see, my options are:

  1. Keep create the same tests for each new class.
  2. Ignore the tests for derived classes, just create the new classes and assume they work.

Option #1 appears to the most “correct”, but also results in fragile tests. Option #2 makes sense in that base object (TypedEventDispatcher) is tested so the derived classes should still work.

So my question is, what is the TDD philosophy for motivating creating new classes based on composition?

Update:
To ask the question in a different way, is it normal to end up with duplicate test code when deriving functionality from existing code?

Update:

BaseEventDispatcher test:

class BaseEventDispatcherTest {
    protected function test_dispatchEvent(dispatcher:Object, event:*):void {
        dispatcher.dispatch(event);
        assertEventDispatched(event)
    }
}

TypedEventDispatcher test:

class TypedEventDispatcherTest extends BaseEventDispatcherTest {
    [Test]
    public function dispatchEvent_TypedEvent_should_dispatch_event():void {
        var event:TypedEvent = new TypedEvent();
        test_dispatchEvent(dispatcher, event);
    }
}

FooEventDispatcher test:

class FooEventDispatcherTest extends BaseEventDispatcherTest {
    [Test]
    public function dispatchEvent_FooEvent_should_dispatch_event():void {
        var event:FooEvent = new FooEvent();
        test_dispatchEvent(dispatcher, event);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:31:28+00:00Added an answer on May 24, 2026 at 5:31 am

    From your comments, it sounds like you are trying to test methods instead of behavior, which is something that can lead to a lot of duplication in tests.

    Rather than having a set of tests like this:

    • test EventDispatcher’s addEventListener
    • test EventDispatcher’s removeEventListener
    • test EventDispatcher’s displatchEvent
    • test TypedEventDispatcher’s addEventListener
    • …

    I would have a set of tests like this:

    • test that dispatchEvent notifies listeners that have been added
    • test that dispatchEvent does not notifiy listeners that have been removed
    • test that removing a listener that was never added is silently ignored

    Those behavioral tests are clearly features of EventDispatcher, and I wouldn’t feel the need of duplicating them for TypedEventDispatcher, FooEventDispatcher, etc.

    But I would want to test the unique features of these other dispatchers, so I might have additional tests like this:

    • test that FooEventDispatcher does not notify listeners of Bar events
    • test that TypedEventDispatcher does not notify listeners of String events
    • …

    (Even better if you could describe those test without mentioning the names of classes, since the tests should be driving the design or your classes, rather than the classes driving the design of your tests.)

    Of course, the goal isn’t to test every possible combination, but only to test the actual features that I need to implement my software, and leave the rest unwritten until needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never developed using Test Driven Development, and I've never used Mock Objects for
Are user stories (typically used in agile development or test driven development) the same
Recently, I have worked in a project were TDD (Test Driven Development) was used.
I am new to grails, coming from Django. Using test driven development, I am
I used Response.Write to write dynamic javascript into a page to test some values
Test Driven Development (TDD) and its benefits are well defined. The same can be
I understand the idea behind test-driven development, write tests first, code against tests until
I'm starting a small/medium-sized python project, likely in Test Driven Development. My backgrounds are
Im am just getting introduced to unit testing and test driven development. Thus far,
Please kindly advise on benchmarks used to test a C and C++ allocator? Benchmarks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.