Test Driven Development

(Difference between revisions)
Jump to: navigation, search
(assessment filled out, changed instructions to match assessment)
(added pre-req)
Line 8: Line 8:
 
|'''Prerequisite Knowledge''' || Students will need to know how to:
 
|'''Prerequisite Knowledge''' || Students will need to know how to:
 
* Program simple Java
 
* Program simple Java
 +
* Develop object-oriented software (classes, methods)
 
|-
 
|-
 
|'''Learning Objectives''' || Students should be able to:
 
|'''Learning Objectives''' || Students should be able to:
Line 41: Line 42:
 
Setup Eclipse and JUnit
 
Setup Eclipse and JUnit
 
* [https://eclipse.org/downloads/ Download and install] Eclipse - JUnit comes with "Eclipse IDE for Java Developers"
 
* [https://eclipse.org/downloads/ Download and install] Eclipse - JUnit comes with "Eclipse IDE for Java Developers"
* (Optional) For tips and gotchas on using JUnit in Eclipse, see the following:
+
* Start a new Java Project and include your name in the Project name. Ex: "NumberCounterNYeates"
 +
* (Optional self-learning) For tips and gotchas on using JUnit in Eclipse, see the following:
 
** http://www.codeaffine.com/2012/11/26/working-efficiently-with-junit-in-eclipse-2/
 
** http://www.codeaffine.com/2012/11/26/working-efficiently-with-junit-in-eclipse-2/
  

Revision as of 23:14, 18 February 2016

Title Test Driven Development (TDD) Introduction using Java in Eclipse/JUnit
Overview Students will follow and implement a beginner level java-based Test Driven Development (TDD) approach with JUnit in the Eclipse IDE. First, they create a test case that fails, then they start creating mock code, and finally a simple piece of code that allows their test to pass.
Prerequisite Knowledge Students will need to know how to:
  • Program simple Java
  • Develop object-oriented software (classes, methods)
Learning Objectives Students should be able to:
  • Install and use the Eclipse IDE and JUnit
  • Use JUnit in Eclipse to implement and run a failing TDD test
  • Use JUnit in Eclipse to implement code that passes a TDD test


Background:

Background reading

Rationale

The method of how developers go about implementing code is varied. Test driven development is one such method stemming in the 2000's that has gained momentum as an accepted and research-proven method for increasing software quality, readability, and reliability. Testing software to assure that it works in certain within particular constraints is an extension of quality assurance (QA) efforts that most professional software products do to increase their products value. With TDD, this testing is built-in even before students to write their first line of code. This means that students will have a better grasp on what they are programming and why. It means that students will have code that not only works when they first implement it, but that will continue to work when others develop next to it and run the same tests.


Directions:

This activity follows a tutorial that steps you through the TDD development process in the Eclipse IDE using its integrated JUnit module. Follow the below tutorials, implementing the TDD test code in Eclipse on your own computer. Finally, you will create actual non-test code that gets the tests to succeed (green JUnit bar). You will hand in this code, the associated test, and two screenshots.


Setup Eclipse and JUnit


Next, follow the Eclipse-JUnit-based TDD tutorial located at:

  • http://www.codeaffine.com/2014/08/12/junit-in-a-nutshell-hello-world/
    • It is an illustrated step-by-step walk through of creating a test and then creating the associated functional code.
  • Implement the same test code and get a failing test, just like in the tutorial.
  • You will be marked up for commenting your code.
  • Take a screenshot of the failing test (red JUnit bar), alongside the test code used to show it.


You should now have a test case that fails, but the stub for the code.

  • Now, you need to make the test succeed. This means implementing the main program code to make the test go green in Eclipse.
  • You will be marked up for commenting your code.
  • Take a screenshot of the succeeding test (green JUnit bar), alongside the code implemented to attain it.

Deliverables:

Code and screenshots:

  • Test code and implementation code that, together, make a successful test case (green in Eclipse JUnit).
  • A screenshot of the test failing (red JUnit bard), before you write the functional code.
  • A screenshot of the test succeeding (green JUnit bar), along side the code you just ran.

Note: You may not use the screenshots provided in the tutorial, as that would be plagiarism. Provide full-screen shots that include the entire Eclipse work space.


Assessment:

Criteria Level 1 (fail) Level 2 (pass) Level 3 (good) Level 4 (exceptional)
Installed and used Eclipse IDE and JUnit tools Did not attempt install or failed install and did not come to instructor Attempted install, had issues, came to teacher for assistance Installed Eclipse but did not use JUnit for rest of assignment Installed Eclipse and successfully utilized JUnit for the rest of the assignment
Implemented failing (red) TDD test code Did not attempt - no screenshot, no code "Red" Screenshot given but TDD test code provided is incorrect/incomplete "Red" Screenshot and the correct TDD test code given "Red" Screenshot and the correct TDD test code given, as well as added comments in the code
Implemented functional code that passed (green) the TDD test code Did not attempt - no screenshot Code

Comments:

What should the instructor know before using this activity?

What are some likely difficulties that an instructor may encounter using this activity?


Additional Information:

ACM Knowledge Area/Knowledge Unit What ACM Computing Curricula 2013 knowledge area and units does this activity cover? ACM_Body_of_Knowledge
ACM Topic What specific topics are addressed? The Computing Curriucula 2013 provides a list of topics - https://www.acm.org/education/CS2013-final-report.pdf
Level of Difficulty Medium
Estimated Time to Completion 4-10 hrs dependent on student familiarity with Java and Eclipse IDE
Materials/Environment

A computer that can run or install the Eclipse IDE for Java Developers (all major OS platforms have easy installers)

Author Nick Yeates
Source http://www.codeaffine.com/2014/08/12/junit-in-a-nutshell-hello-world/ permission to use given by author Frank Appel
License Creative Commons CC-BY

Suggestions for Open Source Community:

Suggestions for an open source community member who is working in conjunction with the instructor.



This work is licensed under a Creative Commons Attribution 4.0 International License


Appendix

Examples of OSS projects that use TDD

Best examples

  • https://github.com/unclebob/fitnesse
    • Written by one of the Agile Manifesto co-authors
    • Very clean code, tests in /test directory
    • Not as well known, but might be easier for students to understand

Weaker examples


TDD "Lessons"

  • https://github.com/orfjackal/tdd-tetris-tutorial
    • Tetris based TDD
    • It gives you test cases, already written, and you code to satisfy the tests
    • License says "You may use and modify this material freely for personal non-commercial use. This material may NOT be used as course material without prior written agreement."


Ideas and research

TDD

  • Idea 1: Find a project that already has a testing harness and associated tests; learn it, and add a new unit test
  • Idea 2: Create a test harness to make, build, and run unit tests on an existing open source project
    • Jim Bowring has done this in the past, though it seems they are lengthy projects vs a shorter activity; Do we want to create a “project”-oriented LA?
  • Idea 3: Use an existing JUnit exercise / tutorial to teach a simple TDD 'test first, code later' scenario
  • Teach the “mental discipline” of testing
  • How can we test a Requirement?
    • Ensuring testing starts at user requirement gathering
    • Iterating through tests once code has been written, helps to improve the tests
  • Dave thinks ManageIQ does unit testing
Personal tools
Namespaces
Variants
Actions
Events
Learning Resources
HFOSS Projects
Evaluation
Navigation
Toolbox