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

  • Home
  • SEARCH
  • 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 8073623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:23:21+00:00 2026-06-05T14:23:21+00:00

So I have been making a game up to a point where I want

  • 0

So I have been making a game up to a point where I want to try TDD, so most of my working code don’t have any test but I would like to try TDD for every new features.

My problem is my game comprises of tons of interdependent systems (sort of like I can’t use the camera without the level in place, objects keep lots of references and initializing things take other things as argument). So just to test the fog system I need to initialize the level, the physic, the camera, the collision (because they all depend on each other to some degrees) and that create lots of duplications. Here’s the code:

test( "shadow test", function() {
    var b2world=new b2World(new b2Vec2(0, 0), false);
    var contactListener = new collisionHandler.CollisionHandler(MASK_BITS);
    b2world.SetContactListener(contactListener);

    var map = gamejs.http.load('images/prot8.json');
    var level = new Level.Level({
        map: map, 
        size: 0.5, 
        nMaskBits: MASK_BITS.node,
        nCategoryBits: MASK_BITS.player | MASK_BITS.birdy | MASK_BITS.innerBody,
        world: b2world,
        scale: SCALE});

    var cam = new Camera.Camera({
            lvlWid: this.level.width*SCALE*this.level.blockSize, 
            lvlHei: this.level.height*SCALE*this.level.blockSize, 
            yBand: 2,
            maxSpeed: 20,
            peerWindow: new b2Vec2(350, 300),
            scrWid: scrWid, 
            scrHei: scrHei});

    var shadow = new Shadow.Shadow({
        width : 300,
        height : 300,
        level : level,
        eye : new b2Vec2(600, 600),
    });

    ok( shadow.blit, "Shadow is extended from surface" );
    ok( shadow.level, "Shadow has reference to the level" );
    ok( shadow.eye, "Shadow has reference to player's eye" );
    ok( (function() {
        for (var i = 0; i < shadow.onScreenBlocks.length; i++) {
            var rect = level.boxes[ shadow.onScreenBlocks[i] ];
            //this is half finished
        }
        return true;
    }), "Shadow do picks the blocks that are visible on screen" );
    ok( (function() {
        for (var i = 0; i < level.boxes.length; i++) if ( shadow.notProcessBlock(i) ) {
            var rect = level.boxes[i];
            if (rect.left < cam.offsetX //at this point I just realized that camera need to be setup in a more complex way...
        }
        return true;
    }), "Shadow only process those blocks that are visible on screen" );
});

overall it just has a bad vibe to it. It’s harder to wrap my mind around and harder to maintain I think.

  • 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-06-05T14:23:23+00:00Added an answer on June 5, 2026 at 2:23 pm

    When writing unit testing in a non-TDD way, you have to ask yourself for each piece of code you write: ‘How can I test this’. This forces you to look at your code and make sure that all dependencies can be replaced when testing.

    When doing TDD, this ‘How can I test this’ is baked in from the beginning. Introducing TDD in the middle of a project leads to problems when you can’t replace all dependencies.

    When Unit Testing, you need to make sure that you can test a unit in complete isolation and replace all dependencies with mocks or fakes. Then you can control all the inputs to your unit test so can you make sure that all code paths are tested.

    To make unit testing work in your project you will have to refactor your code to really support unit testing.

    I think TDD is not the main issue in this case. The question is if you want to use Unit testing at all and I think the answer to that question should be yes! Unit testing has many advantages. Now, you face the problem that the code you have written is hard to test. Making sure your code is testable is something that can be done after you’ve written your code but as you now experience that’s quite hard. That’s the point where TDD can help. TDD will make sure your code is easily testable so you can have all the benefits of unit testing.

    I wrote a blog some time ago about unit testing.. maybe it can help: Unit Testing, hell or heaven?

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

Sidebar

Related Questions

I have been working on making an application for editing game plugins for a
I am making a game that needs a crosshair. I have been playing with
I have tried making a fiddle for this, but it's been too difficult to
Howdy. I've been tasked with making a Facebook game, but I'm new to Facebook
I don't know if this is the correct website, but you guys have been
I have been making a small game for fun. In the game you are
I am almost finished with this game I have been making. It is a
I have been working on a game for iphone and have run into a
I am working on developing a Chess game. I want to have the board
I making a tic tac toe game I have this button, but I could

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.