Test Driven Development

(Difference between revisions)
Jump to: navigation, search
(added rough directions and deliverable)
(directions added to and various meta)
Line 2: Line 2:
 
{| border="1"
 
{| border="1"
 
|-  
 
|-  
|'''Title''' || Test Driven Development (TDD) Introduction with JUnit
+
|'''Title''' || Test Driven Development (TDD) Introduction using Java in Eclipse/JUnit
 
|-
 
|-
 
|'''Overview''' || Students will follow a beginner level JUnit (java-based) TDD development approach. 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.
 
|'''Overview''' || Students will follow a beginner level JUnit (java-based) TDD development approach. 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:
 
|'''Prerequisite Knowledge''' || Students will need to know how to:
* Program java in the Eclipse IDE environment
+
* Program simple Java
 
|-
 
|-
|'''Learning Objectives''' || What should the student be able to do after completing this activity?
+
|'''Learning Objectives''' || Students should be able to:
 +
* Use JUnit in Eclipse to implement and run a failing test
 +
* Use JUnit in Eclipse to implement a
 
|}
 
|}
 +
 +
  
 
=== Background: ===
 
=== Background: ===
Line 20: Line 24:
  
 
Include helpful hints to faculty here.
 
Include helpful hints to faculty here.
 +
  
  
 
=== Directions: ===
 
=== Directions: ===
This activity follows  
+
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; Follow this tutorial:
+
 
 +
Setup Eclipse and JUnit
 +
* JUnit comes with "Eclipse IDE for Java Developers"; simply [https://eclipse.org/downloads/ download] and install.
 +
* Follow the below tutorial, or find your own.
 
* 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/
 +
  
 
Next, follow the Eclipse-JUnit-based TDD tutorial located at:
 
Next, follow the Eclipse-JUnit-based TDD tutorial located at:
 
* http://www.codeaffine.com/2014/08/12/junit-in-a-nutshell-hello-world/  
 
* http://www.codeaffine.com/2014/08/12/junit-in-a-nutshell-hello-world/  
 
** It is a superbly written and illustrated step-by-step walk through of creating a test and then creating the associated functional code.
 
** It is a superbly written and illustrated step-by-step walk through of creating a test and then creating the associated functional code.
 +
** Provided with permission from Frank Appel.
 +
* Take a screenshot of the failing test code (red JUnit bar).
 +
 +
 +
Finally, implement code that allows your test to succeed
 +
* 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.
  
* Implement code that allows your test to succeed
 
** 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.
 
  
  
 
=== Deliverables: ===
 
=== Deliverables: ===
Code and screenshot:
+
Code and screenshots:
 
* Test code and implementation code that, together, make a successful test case (green in Eclipse JUnit).
 
* Test code and implementation code that, together, make a successful test case (green in Eclipse JUnit).
* Take a screenshot of the green JUnit bar along side the code you just ran.
+
* 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.
 +
 
 +
 
  
 
=== Assessment: ===
 
=== Assessment: ===
Line 50: Line 66:
  
 
{| border="1" class="wikitable"
 
{| border="1" class="wikitable"
! Criteria
+
! Criteri
 
! Level 1 (fail)
 
! Level 1 (fail)
 
! Level 2 (pass)
 
! Level 2 (pass)
Line 88: Line 104:
 
|'''Estimated Time to Completion''' ||  How long should it take for the student to complete the activity?
 
|'''Estimated Time to Completion''' ||  How long should it take for the student to complete the activity?
 
|-
 
|-
|'''Materials/Environment''' || What does the student need?  Internet access, IRC client, Git Hub account, LINUX machine, etc.?
+
|'''Materials/Environment''' ||  
 +
* Eclipse IDE installed
 +
* JUnit module in Eclipse
 
|-
 
|-
|'''Author''' || Who wrote this activity?
+
|'''Author''' || Nick Yeates
 
|-
 
|-
 
|'''Source''' || Is there another activity on which this activity is based?  If so, please provide a link to the original resource.
 
|'''Source''' || Is there another activity on which this activity is based?  If so, please provide a link to the original resource.

Revision as of 20:23, 18 February 2016

Title Test Driven Development (TDD) Introduction using Java in Eclipse/JUnit
Overview Students will follow a beginner level JUnit (java-based) TDD development approach. 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
Learning Objectives Students should be able to:
  • Use JUnit in Eclipse to implement and run a failing test
  • Use JUnit in Eclipse to implement a


Background:

Is there background reading material?

Are there other activities the student should have done first?

What is the rationale for this activity?

Include helpful hints to faculty here.


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:


Finally, implement code that allows your test to succeed

  • 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.


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.


Assessment:

How will the activity be graded?

How will learning will be measured?

Include sample assessment questions/rubrics.

Criteri Level 1 (fail) Level 2 (pass) Level 3 (good) Level 4 (exceptional)
The purpose of the project
Why the project is open source

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 Is this activity easy, medium or challenging?
Estimated Time to Completion How long should it take for the student to complete the activity?
Materials/Environment
  • Eclipse IDE installed
  • JUnit module in Eclipse
Author Nick Yeates
Source Is there another activity on which this activity is based? If so, please provide a link to the original resource.
License Under which license is this material made available? (http://creativecommons.org/licenses/)

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-ShareAlike 4.0 International License

CC license.png



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."


Background reading


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