Archive for September, 2006

Test Driven Development is something that is both old and new to me. It’s old in the sense that I’ve been writing code in a test-first fashion since I was an undergraduate CS major. Although, back then my tests were more like Console.WriteLine, to make sure something I expected to happen would happen. I always started with an expectation of what the code should do and wrote the code to fit the expectation. But those little console outputs always got deleted once I was through with them. They were useless as regression tests and they did nothing to help document the code’s behavior, let alone give me confidence to refactor later on during development.

Today, TDD is a mainstream technique. It has grown up and matured. I’m sure that what I used to do for “test first” development would be laughed at by developers in the TDD sphere today. That’s fine. But what I did then helped shape how I write code, and made it very easy for me to see the logic and usefulness of TDD. I’ve long had the mindset of expectation first, write code to meet it.

Today, TDD is an automated practice. Unit Tests are now real code that gets compiled and run, and those tests hang around for as long a the application does. They’re great regression tools, documentation, and confidence builders for refactoring. They are as important to the development of the code as the code itself.

But if you’re new to this “automated” way of testing, like I am, you may find the whole thing difficult to manage. There are serious questions that arise when you’re building a non-trival application, particularly a data-driven application. How do I test complex classes and objects that have a lot of interaction between each other? What should I mock and how do I mock properly? How do I test private methods, or should I even try? How much abstraction is necessary? Maybe most important: Am I actually testing the code properly? Am I exercising it fully?

For the past year or so I’ve been using, sporadically, NUnit as my testing framework. It’s nice, easy to use, clean code, and I dig the GUI. Seeing green and knowing my tests are passing is fun work. But even with a good test framework, and even using good design principles like Dependency Injection, making use of Interfaces and judicious use of design patterns, one eventually runs into cases where you just have to wonder if this testing business is worth the effort. Classes get complicated – not because they’re big or doing a lot of stuff (if they’re elephants then that’s probably a code smell anyway) but because they’re interacting with so many moving pieces. If you’re like me, you may find yourself sitting at your monitor able to quickly realize how you would code the solution to a particular problem, but unable to figure how you would write the tests for that solution – and write those tests first. This can lead to a lot of head scratching and doubt, wondering about the usefulness of Test Driven Development.

And even if you do manage to forge ahead and code a solution, you can feel overwhelmed at how to properly test it. Then you’re not doing TDD anyway, you’re just trying to keep your head above water and write tests after the fact.

That is the situation I’ve found myself in for quite some time. Until now. The solution to this particular problem, at least for me, has come in the form of a test coverage device called NCover.

NCover

NCover lets you know how much of your code is being tested by your unit tests. With the help of a GUI editor called NCoverExplorer, it will show you, line by line, how much of your code is being exercised by your tests. More importantly, however, it may make you rethink how you’re testing, and this can be invaluable for a newbie like me.

When I started trying TDD the hardest part was figuring out how to test complex code, especially data-driven code. It becomes really complicated when you have some class with several private methods that are manipulating a large domain object and utilizing a few injected classes and services to help. It becomes a very complex piece of code, and it can be difficult to break it down mentally into the simplest of terms. What one has to ask is, “What is really happening here, and how can I write code to exercise and test that behavior?”

You can wrack your brain silly trying to figure out if you should expose private methods for testing, or refactor your class into smaller parts, or whatever. There’s a gaggle of blogposts and articles about these sorts of subjects, and it all gets very religious very fast. For a newbie, that can make it all the more confusing, because all we really care about is: “Am I testing this correctly?” Because once we can figure out how to actually test correctly, then we can start to figure out how to test first. And that drives the design. That’s where we want to be.

The trick is learning the difference between just testing lines of code and testing a behavior. With a code coverage tool like NCover, it becomes a lot easier to start thinking in the latter form. I’m finding that the code coverage tool helps me think about things I didn’t think about before. It’s made me qestion if I’m overdesigning something (because I have to write test code to cover the solution, and maybe there’s a simpler way), or if I’m testing the behavior correctly – getting after edge scenarios and making sure misbehavior is as predictable as the desired behavior.

The biggest thing, however, is that I no longer worry so much about private methods. As some TDD gurus have said in other blogs, private methods can be tested through public interfaces. That sounds logical, but in practice it can be a bit more difficult to accomplish. Until you have code coverage, that is. When you can actually see the lines of code in the private methods being exercised, yet realize that your public methods are what you’re really testing and it is their behavior that you’re really interested in, then the process finally seems to work in a realistic fashion.

I don’t worry about private methods now – I just make sure that the code in them is being exercised completely through the public interfaces. Or more precisely – through the behavior that I am expecting the object to exhibit. Writing test cases through the public methods to exercise private methods makes me think about the behavior of the class as a whole, and what I’m really trying to accomplish. And that has made writing tests a lot easier.

And a lot more fun.

Mensa

When I finished college I thought I had pretty much taken my last test. And thank goodness, because after several years of school I was really tired and burned out on the whole acedemic lifecycle: attend lecture, do homework, study, test, rinse & repeat. Doing my work in the real world – coding, testing, and designing software systems – is much more intellectually challenging, dynamic and interesting. It’s just flat out more fun. I learn more every day doing this line of work than I ever did in a semester of school (not to say school wasn’t valuable – it was – but at times I felt like we spent way too much time on things that weren’t really important).

But two Sundays ago I found myself in a classroom on the 3rd floor of an engineering building at Gonzaga University. And for the first time in my life I was actually excited to take a test; I was actually looking forward to it.

The test was the Mensa admission test.

The start of this journey dates back, oddly enough, to Donald Trump’s television show, The Apprentice. Tarek Saab was one of the contestants, and when he introduced himself to Trump and the other contestants he added, “I’m also a member of Mensa.” That got me interested. I’d heard of Mensa, but only vaguely knew what it was. So I checked it out online, and it turns out it’s a society – a club if you will – for folks whose IQ’s fall into the top 2%. I thought that was interesting, because I value intelligence a lot. Like honor and trust, it’s something I think is pretty important.

A few months later I stumbled across an online IQ test and scored pretty well. But I knew a lot of online tests are bogus and report inflated results. Their goal is to get you to spend money on some other bogus test, or to earn ad revenue through clicks. So I didn’t consider it an accurate borometer – but it did prod me to take further action. The next step was to order the Mensa Home test. The results were encouraging, so I opted to try for the real thing.

Yesterday the results were in, and I made the cut.

I post this mostly for friends and family, who had no idea I was doing this. Mostly, this is just my thanks to my mom and dad, who always encouraged me to think. Some parents encourage their kids to be superstar atheletes. Others encourage a particular profession, like doctor or lawyer. My parents encouraged me to think creatively in general, and to focus on the things that interested me.

Some people, like Tarek Saab, are wunderkinds; smart from birth. Tarek, it says in the Wiki, was testing at the collegiate level at grade seven. That wasn’t me. I did O.K. in school, but I was no valedictorian. Scholorships did not reign down on me upon graduation, and even college was tough (although I did choose Computer Science, which is not exactly basket weaving).

Apparently, like a wine or ale, my intelligence required aging. And that aging process happened because my parents encouraged me to think, to use my brain to figure things out, and to be curious about subjects I found interesting. They made it ok to be smart.

And I think that’s pretty cool.

As detailed a couple weeks ago, Madden 2007 has included a new feature for Franchise mode: Player Roles. These roles can affect several aspects of the game, making them more than just a gimmick. The two most common affects of a role is to boost the player’s ratings and increase or decrease their value (which in turn affects their salary requirements and trade value). The stat boosts can affect more than just the player carrying the role tag; his teammates ratings or even the opposition he’s facing can also be affected depending on the specific role. Role effects can also occur at specific times during the game. For instance, on 3rd down or in the fourth quarter a player might get a boost because they perform better under pressure.

Good luck finding the descriptions of these roles in the manual though – they don’t exist. You won’t find them in the in-game help either, but you will occassionally see a description of one of them displayed between screen transitions, which on a fast computer leaves barely enough time to read it. Convenient huh? I didn’t think so either. However, thanks to Drewbaby27 at football-freaks.com, I was able to discover an Excel spreadsheet of the roles and their descriptions. To save you, Madden Fan, from having to download the file I’m posting the roles here. Enjoy.

QB of the Future

  • This player is considered the QB of the Future by his franchise.
  • This role is applied to a QB that is drafted in the 1st round and is a prototype NFL QB.
  • This player will lose his role if another QB is drafted in the 1st round while he’s on the roster or if he fails to meet expectations by his 4th YIL (Year In League).
  • This role increases this player’s value in trades by 25 percent.
  • This player expects to be starting by his 3rd YIL.

Feature Back

  • This player is considered the Feature Back.
  • This player will lose his role if: His OVR drops below 84, His franchise signs another Feature Back or his franchise drafts a HB in the 1st round.
  • This player expects to start every game and he expects 75 percent of the team’s carries.
  • His starting OL receives +2 AWR and +2 RBK while he has this role.

Franchise Quarterback

  • This player is considered the Franchise QB.
  • This player will lose his role if: his OVR drops below 85, his franchise signs another Franchise QB or his franchise drafts a QB in the 1st round.
  • This role increases this player’s value by 10 percent.
  • His starting OL receives +2 AWR and +2 PBK and his starting WRs, TE, HB and FB receive +2 CTH and +2 AWR while he has this role.

Go to Guy

  • This player will lose his role if he has 5 or more drops in a season or less than 20 first downs.
  • This role increases his value 2 percent.
  • This player expects to start every game, average 3 catches and 2 first downs per game played.
  • His starting QB receives a THA boost of +3 while the Go to Guy receives a boost of +2 AWR and +2 CTH on any pass thrown to him in-game.

NFL Starter

  • This player is considered an NFL Starter.
  • This player earns this role if he has 12 starts in a season and is a starter in the depth chart at the end of the season.
  • This role increases his value 3 percent.
  • This player expects to maintain his starting position.
  • This player receives a boost of AWR +1 with this role.

Clutch Kicker

  • This player is considered a Clutch Kicker.
  • This player earns this role if he makes 3 Game Winning Kicks and loses it if he misses 3 Game Winning Kicks.
  • This role increases his value 5 percent.
  • This player expects to take 80 percent of team FG attempts.
  • This player receives a boost of KAC +3 and KPW +2 for every 4th quarter FG attempt in-game.

Team Captain

  • This player is considered a Team Captain.
  • This role increases his value 1 percent.
  • This player receives AWR +1 while he has this role.

NFL Icon

  • This player is considered an NFL Icon.
  • This role increases his value 10 percent.
  • While this player has this role, every starter on his side of the ball will receive AWR +1.

Deep Threat

  • This player will lose his role if: His SPD drops below 91 or he averages less than 8 YPC for the season.
  • This role increases his value by 4 percent.
  • This player expects to average 3 catches per game.
  • His starting QB will receive THP +1 and THA +1 for every game he starts, while he’ll receive CTH +1 and AWR +1 in those games.
  • A defender in man coverage will receive SPD -1 and AWR -1 for that play.

Possession Receiver

  • This role increases this player’s value by 3 percent.
  • This player expects to average 2 first downs for every GP.
  • For every pass thrown to him in-game, his QB receives THA +1 while he receives CTH +1 and AWR +1.
  • Any defender manned up on him when a pass is thrown to him has AWR -1.

Shutdown Corner

  • This role is earned and lost based on catches allowed.
  • This role increases his value 6 percent.
  • Any player he’s assigned to in man coverage in-game receives AGI -1, ACC -1, STR -1, CTH -1, AWR -1 for that play.
  • The opposing QB will receive THA -1 for every pass thrown his way.
  • He’ll receive AWR +1, AGI +1, ACC +1 and SPD +1 while he has this role.

Underachiever

  • This player earned this role because his overall is 82 or less years after he was a 1st round draft pick.
  • The player can shed this role once his OVR is at least 86.
  • This role decreases this player’s value by 8 percent.
  • Players on the team will receive temporary attribute drops while this player has this role.

Pass Rusher

  • This role will be removed if his OVR is 88 or less and he records less than 2 sacks in a season.
  • This role increases this player’s value by 4 percent.
  • For every pass play he’s in for, the opposing O-Line will receive PBK -1 while he receives AWR +1, AGI +1, ACC +1 and TAK +1.
  • The members of the secondary on the field with him will receive AWR +1 for every pass play.

Team Mentor

  • This player is considered a Team Mentor.
  • This role will be removed if his OVR is 85 or less and his MOR is 25 or less at the end of the season.
  • This role increases this player’s value by 5 percent.
  • While this player has this role, young players at his position will receive AWR +2 while veterans at his position will receive AWR +1.

Run Stopper

  • This player is considered a Run Stopper.
  • This role increases his value 6 percent.
  • The opposing O-Line receives RBK -1 while the opposing HB receives AGI -1 for every run play the Run Stopper is in the game for.
  • This player receives AWR +1, AGI +1, ACC +1 and TAK +1 while they have this role.
  • LBs and Safeties receive AWR +1, +2 SPD and +2 AGI for every run play they are on the field with the Run Stopper.

Team Leader

  • This player is considered a Team Leader.
  • This role will be removed if his OVR is 85 or less and his MOR is 25 or less at the end of the season.
  • This role increases this player’s value by 5 percent.
  • While this player has this role, young players on the team will receive AWR +1.

Project Player

  • This player is considered a Project Player.
  • That means he’s a player with plenty of physical talent but a low OVR.
  • This role will be removed if his OVR exceeds 88 at any point in his career.
  • This role increases this player’s value by 2 percent.

Team Distraction

  • This player has become a Distraction.
  • He’s become a distraction because his morale has dropped to dangerous levels.
  • Once this player’s morale increases to normal levels, this role will be removed.
  • This role decreases this player’s value by 8 percent.
  • While he has this role, every player on the team will receive a drop of AWR -1.

Captain Comeback

  • This player is considered Captain Comeback.
  • This player earns this role if he makes 10 4th Qtr. Comebacks.
  • This role increases his value 6 percent.
  • This player expects to make at least one 4th Qtr. Comeback per season.
  • This player receives a boost of AWR +3 and THA +2 in the 4th Qtr of game where his team is losing.
  • His teammates on offense receive AWR +1.

Game Manager

  • This player is considered a Game Manager.
  • This player loses this role once his overall exceeds 89 or drops below 81.
  • This role increases his value 4 percent.
  • This player expects to play in at least 4 games per season.
  • This player receives a boost of AWR +1 and THA +1 on third down passing plays.

Return Specialist

  • This player is considered a Return Specialist.
  • This role will be removed when the player averages 15 yards or less per KR or 5 yards or less per PR for the season.
  • This role increases the player’s value 12%.
  • During a return, this player will receive AWR +3, AGI +2, ACC +2 and BTK +2.
  • His blockers will receive +2 RBK while his opponents receive TAK -2.

Offensive Playmaker

  • This player is considered an Offensive Playmaker.
  • This role will be removed if this player throws 15 INT or has 5 Fumbles.
  • This player expects to start every game.
  • This role increases the player’s value 6%.
  • Depending on his position, this player will receive attribute boosts in-game for 3rd down plays and for the 4th Qtr.

1st Round Pick

  • This player is a 1st Round Pick.
  • This player expects to start every game by his 3rd YIL.
  • This role increases the player’s value 7%.

Defensive Enforcer

  • This player is considered a Defensive Enforcer.
  • This role will be removed if this player’s OVR drops below 80, his TAK drops below 85 and he records 3 Big Hits or less in a season.
  • This player expects to start every game and record at least 10 big hits per season.
  • This role increases the player’s value 3%.
  • This player will receive TAK +3 while he has this role.

Fan Favorite

  • This player received this role because his OVR is at least 90 and he has been with the same team for 5 seasons.
  • This player does not want to be on the trading block.
  • His value will increase by 10% while he has this role.

  • While he has this role, his AWR +1 and the team’s attendance will increase.

Injury Prone

  • This player is considered Injury Prone.
  • He earned this role because his INJ is 70 or less while his TGH is 80 or less.
  • Once his INJ exceeds 80, this role will be removed.
  • This player’s value is decreased by 10%.
  • CPU teams will only sign this player to a 1-year deal.

Fumble Prone

  • This player earned this role because his CAR is less than 76 and he had at least 5 fumbles this season.
  • Once his CAR exceeds 80 and he records 3 fumbles or less in a season, this role will be removed.
  • This player’s value is decreased by 10%.
  • While he has this role, this player’s CAR will decrease by 5 on 3rd down running plays and in the 4th Qtr.

Defensive Playmaker

  • This player is considered a Defensive Playmaker.
  • This role will be removed if this player goes an entire season without a FF or INT.
  • This player expects to start every game.
  • This role increases the player’s value 7%.
  • Depending on his position, this player will receive attribute boosts in-game for 3rd down plays and for the 4th Qtr.

Future Star

  • This player is considered a Future Star in the NFL.
  • This role is applied to a player that is drafted in the 1st round and who has exceptional talent.
  • This player will lose his role if he fails to meet expectations by his 4th YIL.
  • This role increases this player’s value in trades by 25 percent.
  • This player expects to be starting by his 3rd YIL.