Test Driven Development
(research link; oss testing link) |
(added rough directions and deliverable) |
||
Line 1: | Line 1: | ||
+ | __NOTOC__ | ||
+ | {| border="1" | ||
+ | |- | ||
+ | |'''Title''' || Test Driven Development (TDD) Introduction with 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 java in the Eclipse IDE environment | ||
+ | |- | ||
+ | |'''Learning Objectives''' || What should the student be able to do after completing this activity? | ||
+ | |} | ||
+ | |||
+ | === 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 | ||
+ | |||
+ | Setup Eclipse and JUnit; Follow this tutorial: | ||
+ | * http://www.codeaffine.com/2012/11/26/working-efficiently-with-junit-in-eclipse-2/ | ||
+ | |||
+ | 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 a superbly written and illustrated step-by-step walk through of creating a test and then creating the associated functional code. | ||
+ | |||
+ | * 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 screenshot: | ||
+ | * 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. | ||
+ | |||
+ | === Assessment: === | ||
+ | How will the activity be graded? | ||
+ | |||
+ | How will learning will be measured? | ||
+ | |||
+ | Include sample assessment questions/rubrics. | ||
+ | |||
+ | {| border="1" class="wikitable" | ||
+ | ! Criteria | ||
+ | ! 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: === | ||
+ | {| border="1" | ||
+ | |- | ||
+ | |'''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''' || What does the student need? Internet access, IRC client, Git Hub account, LINUX machine, etc.? | ||
+ | |- | ||
+ | |'''Author''' || Who wrote this activity? | ||
+ | |- | ||
+ | |'''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 | ||
+ | [http://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0 International License] | ||
+ | |||
+ | [[File:CC_license.png]] | ||
+ | |||
+ | [[Category: Learning_Activity]] | ||
+ | [[Category: LEARNING_ACTIVITY_SUBCATEGORY]] | ||
+ | |||
+ | |||
+ | |||
Revision as of 01:30, 18 February 2016
Title | Test Driven Development (TDD) Introduction with 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:
|
Learning Objectives | What should the student be able to do after completing this activity? |
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
Setup Eclipse and JUnit; Follow this tutorial:
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 a superbly written and illustrated step-by-step walk through of creating a test and then creating the associated functional code.
- 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 screenshot:
- 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.
Assessment:
How will the activity be graded?
How will learning will be measured?
Include sample assessment questions/rubrics.
Criteria | 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 | What does the student need? Internet access, IRC client, Git Hub account, LINUX machine, etc.? |
Author | Who wrote this activity? |
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
Examples of OSS projects that use TDD
Best examples
- http://junit.org/
- Well-known java unit testing framework written by Kent Beck, inventor or TDD himself
- https://github.com/junit-team/junit
- https://github.com/junit-team/junit/tree/master/src/test
- ex of actual test code: https://github.com/junit-team/junit/blob/master/src/test/java/junit/tests/framework/AssertTest.java
- 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
- https://github.com/rails/rails
- It is said that much of anything rails is developed via TDD
- https://travis-ci.org/rails/rails
- https://github.com/rails/rails/pull/23690
- http://www.sqlite.org/testing.html
- Superb write up by SQLite of how they do extensive testing, but its possibly not developed with TDD principles, or maybe partially.
- https://github.com/AutoFixture/AutoFixture
- Another TDD example project, but its around .NET .... meh
- https://github.com/AutoFixture/AutoFixture/blob/master/Src/AutoFixture.xUnit.net.UnitTest/AutoDataAttributeTest.cs
TDD "Lessons"
- http://www.codeaffine.com/2014/08/12/junit-in-a-nutshell-hello-world/ , http://www.codeaffine.com/2012/11/26/working-efficiently-with-junit-in-eclipse-2/
- A superbly written step-by-step walk through of creating a test and then creating the associated functional code
- It uses JUnit, which is an open source technology - but it uses a helloworld example - not sure if we want this or more of an integration with an existing oss project
- Code Affine gave us permission to use!
- https://schuchert.wikispaces.com/Cxx+TDD+Monopoly
- Line-by-line explanation of code and tests and process to create Monopoly features via TDD
- Not sure what students would do, as all answers are given
- CC-BY-SA
- https://dzone.com/articles/Write-JUnit-Tests-in-Spring-With-Mocked-and-Real-Objects
- Specific to spring framework, and not for beginners; possibly complex to implement for beginners
- I think DZone is copyright encumbered :-/ all content on it is proprietary in their submission legal text
- http://technologyconversations.com/2013/12/20/test-driven-development-tdd-example-walkthrough/ http://osherove.com/tdd-kata-1/ https://vimeo.com/8506325
- These are a great series of TDD "Practice Exercises"; It gives you requirements that you are supposed to serially step through and implement on top of each other
- This uses open source, but it isn't involved in any existing oss project
- Unknown copyright
- 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
- 5 min TDD overview https://www.youtube.com/watch?v=QCif_-r8eK4
- Graphical explanation of TDD http://www.agiledata.org/essays/tdd.html
- Is TDD Dead? https://www.youtube.com/watch?v=z9quxZsLcfo
- Kent Beck book http://www.amazon.com/exec/obidos/ASIN/0321146530/
- Astels book http://www.amazon.com/exec/obidos/ASIN/0131016490/
- Unit test vs Acceptance test https://dzone.com/articles/Write-JUnit-Tests-in-Spring-With-Mocked-and-Real-Objects
- TDD in a CalPoly course https://users.csc.calpoly.edu/~djanzen/courses/405W10/presentations/TDD.pdf
- Research showing TDD's pro's and con's https://tuhat.halvi.helsinki.fi/portal/files/29553974/2014_01_swqd_author_version.pdf
- Lists all open source testing tools - http://www.opensourcetesting.org/
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
- Background reading:
- http://www.cs.cofc.edu/~bowring/ - course in testing
- Boris Byser - the test guru
- Kent Beck - extreme programming (ford motor)
- http://foss2serve.org/index.php/Test_Coverage_Activity