Test Driven Development

(Difference between revisions)
Jump to: navigation, search
(criteria in assessment)
(18 intermediate revisions by 3 users not shown)
Line 6: Line 6:
 
|'''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.
 
|'''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:
+
|'''Prerequisite Knowledge''' || Students should be familiar with:
* Program simple Java
+
* Programming simple Java
 +
* Developing object-oriented software (classes, methods, instances)
 +
* Test Driven Development (TDD) workflow and theory
 
|-
 
|-
|'''Learning Objectives''' || Students should be able to:
+
|'''Learning Objectives''' || Upon completion, students should be able to:
* Install and use the Eclipse IDE and JUnit
+
* Install and use Eclipse IDE and JUnit
 
* Use JUnit in Eclipse to implement and run a failing TDD test
 
* Use JUnit in Eclipse to implement and run a failing TDD test
 
* Use JUnit in Eclipse to implement code that passes a TDD test
 
* Use JUnit in Eclipse to implement code that passes a TDD test
 
|}
 
|}
  
 +
[[File:TDDEclipseJUnit.png|500px]]
 +
 +
----
  
 
=== Background: ===
 
=== Background: ===
  
==== Background reading ====
+
Is there background reading material?
* 5 min TDD overview video https://www.youtube.com/watch?v=QCif_-r8eK4
+
* Graphical explanation of TDD http://www.agiledata.org/essays/tdd.html
+
* Kent Beck book (he invented TDD) http://www.amazon.com/exec/obidos/ASIN/0321146530/
+
* Astels TDD 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
+
* Is TDD Dead? https://www.youtube.com/watch?v=z9quxZsLcfo
+
* List of all open source testing tools - http://www.opensourcetesting.org/
+
* See appendix for more resources
+
  
==== Rationale ====
+
It is assumed, as per the prerequisites above, that students have already learned about TDD. However, if teacher or students need some content to start on, the best quick dummies guide would be this [https://www.youtube.com/watch?v=QCif_-r8eK4 YouTube video summarizing TDD], and this [http://www.agiledata.org/essays/tdd.html graphical explanation of the TDD process]. If you want more extensive TDD learning content, check out Kent Beck's [http://www.amazon.com/exec/obidos/ASIN/0321146530/ "Test-Driven Development by Example"]. He is the inventor of TDD and wrote JUnit, the focus of this exercise. Additionally, see how a [https://users.csc.calpoly.edu/~djanzen/courses/405W10/presentations/TDD.pdf CalPoly] and [http://www.cs.cofc.edu/~bowring/ College of Charleston] class used TDD in their studies. For more resources, and ideas on secondary TDD exercises, see the [[#Appendix|Appendix]] of this page.
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 [https://tuhat.halvi.helsinki.fi/portal/files/29553974/2014_01_swqd_author_version.pdf 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.
+
  
 +
What is the rationale for this activity?
  
 +
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 [https://tuhat.halvi.helsinki.fi/portal/files/29553974/2014_01_swqd_author_version.pdf research-proven] method for increasing software quality, readability, and reliability. Testing software to assure that it works within particular constraints is an extension of quality assurance (QA) efforts that most professional software products enact to increase their products value. With TDD, this testing is built-in even ''before'' students 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: ===
 
=== 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.
+
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 while implementing the TDD test code in Eclipse on your own computer. Finally, you will create standard functional code that gets the tests to succeed (green JUnit bar). You will hand in this code, the associated test code, and two screenshots.
 
+
  
Setup Eclipse and JUnit
+
==== Step 1: Setup Eclipse and JUnit ====
 +
First, you will need to setup and understand your coding environment. If you have not setup the Eclipse IDE for java before, read through some of the below links. You need to be able to run code and tests with the IDE. There can be some unexpected "gotchas".
 
* [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:
+
* Become familiar with the Eclipse Workbench and in Running code - there is a built-in Eclipse Help Guide, as well as 3rd party tutorials.
** http://www.codeaffine.com/2012/11/26/working-efficiently-with-junit-in-eclipse-2/
+
* If you get stuck on anything:
 +
** Watch [https://www.youtube.com/watch?v=tkzJsP7NP54 How to Create and Run a Simple JUnit test in Eclipse IDE].
 +
** Try the tips in the [[#Comments:|Comments section]] below if you get really stuck.
 +
* Start a new Java Project and include your own name in the 'Project name' field.
 +
** Ex: "NumberCounter-NYeates"
  
  
Next, follow the Eclipse-JUnit-based TDD tutorial located at:
+
==== Step 2: Make the test ====
 +
As per TDD you will write a failing test first, before writing any real code that achieves your purpose. The meat of this activity is in the Code Affine tutorial below:
 
* 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 an illustrated step-by-step walk through of creating a test and then creating the associated System Under Test (SUT) code (the code which implements the functionality that you actually want).
** Provided with permission from Frank Appel.
+
* Create a file called "NumberRangeCounterTest.java" to put the test code into.
* Take a screenshot of the failing test (red JUnit bar), alongside the test code used to show it.
+
* Create a separate file called "NumberRangeCounter.java" to put the skeleton SUT code into.
 +
* Implement the test class code and the skeleton SUT code found in the tutorial and get a failing test.
 +
* You will be marked up for commenting your code.
 +
* Take a screenshot of the failing test (red JUnit bar) and code.
  
  
You should now have a test case that fails, but the stub for the code.
+
==== Step 3: Write 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 should now have a test case that fails and a stub/skeleton for the System Under Test (SUT) code. Now, you need to make the test succeed. This means implementing the SUT code (the code that actually implements the functionality wanted) to make the test go green in Eclipse.
 +
* Create working SUT code in the "NumberRangeCounter.java" file.
 +
* 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.
 
* Take a screenshot of the succeeding test (green JUnit bar), alongside the code implemented to attain it.
 +
 +
 +
(Optional self-learning) For tips and tricks on using JUnit in Eclipse, see the following:
 +
* http://www.codeaffine.com/2012/11/26/working-efficiently-with-junit-in-eclipse-2/
  
  
  
 
=== Deliverables: ===
 
=== Deliverables: ===
Code and screenshots:
+
After having gone through the above tutorials and coding exercise, students will hand in the following code and screenshots:
* Test code and implementation code that, together, make a successful test case (green in Eclipse JUnit).
+
* Test code and implementation (SUT) 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 failing (red JUnit bard), before you write the SUT code.
 
* A screenshot of the test succeeding (green JUnit bar), along side the code you just ran.
 
* 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.
  
  
Line 75: Line 87:
 
|-
 
|-
 
| '''Installed and used Eclipse IDE and JUnit tools'''
 
| '''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'''
 
| '''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'''
+
| '''Implemented SUT code that passes the (green) TDD test code'''
|  
+
| Did not attempt - no screenshot, no code
|  
+
| Attempted and SUT code exits, but was never able to get "Green" bar from JUnit
|  
+
| SUT code exists and screenshot shows successful "Green" bar
|  
+
| SUT code exists, screenshot shows successful "Green" bar, and comments have been added to the code
  
 
|}
 
|}
Line 98: Line 110:
 
=== Comments: ===
 
=== Comments: ===
 
What should the instructor know before using this activity?
 
What should the instructor know before using this activity?
 +
* Step through this activity yourself beforehand, as students will have some gotchas upon installing Eclipse and trying to use JUnit
  
 
What are some likely difficulties that an instructor may encounter using this activity?
 
What are some likely difficulties that an instructor may encounter using this activity?
 +
* Students may not be able to setup and start running code in Eclipse easily
 +
** Watch the [https://www.youtube.com/watch?v=tkzJsP7NP54 How to Create and Run a Simple JUnit test in Eclipse IDE] video to get ideas
 +
** Assure that you add the JUnit Buildpath Library to your project
 +
** Assure that two lines exist at the top of your tests source code file
 +
**:<pre>
 +
**:: import static org.junit.Assert.*;
 +
**:: import org.junit.Test;</pre>
 +
  
  
Line 105: Line 126:
 
{| border="1"
 
{| 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 Knowledge Area/Knowledge Unit''' || SE - Software Engineering, from [[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
+
|'''ACM Topic''' || SE/Testing types, SE/Testing Fundamentals, SE/Test-driven development - https://www.acm.org/education/CS2013-final-report.pdf
 
|-
 
|-
 
|'''Level of Difficulty''' || Medium
 
|'''Level of Difficulty''' || Medium
 
|-
 
|-
|'''Estimated Time to Completion''' ||  4-10 hrs dependent on student familiarity with Java and Eclipse IDE
+
|'''Estimated Time to Completion''' ||  2-6 hrs dependent on student familiarity with Java and Eclipse IDE
 
|-
 
|-
 
|'''Materials/Environment''' ||  
 
|'''Materials/Environment''' ||  
A computer that can run or install the Eclipse IDE for Java Developers (all major OS platforms have easy installers)
+
A computer that can run or install the Eclipse IDE for Java Developers (all major operating systems have easy installers)
 
|-
 
|-
 
|'''Author''' || Nick Yeates  
 
|'''Author''' || Nick Yeates  
Line 125: Line 146:
 
=== Suggestions for Open Source Community: ===
 
=== Suggestions for Open Source Community: ===
 
Suggestions for an open source community member who is working in conjunction with the instructor.
 
Suggestions for an open source community member who is working in conjunction with the instructor.
 +
* Show students any unit testing or TDD-based development you may already have in place. A real life example, with an explanation from a community developer would be a perfect way to solidify the understanding that testing is necessary for real world software.
  
  
Line 136: Line 158:
 
[[Category: Quality_and_Testing]]
 
[[Category: Quality_and_Testing]]
 
[[Category: Specification_and_Design]]
 
[[Category: Specification_and_Design]]
 +
 +
  
  
 
=== Appendix ===
 
=== Appendix ===
 +
The below appendix includes information found while researching and creating the above Learning Activity. Instructors may find it useful if they are wanting to create their own follow-on activities or want more info.
 +
 +
 +
=== Background Reading ===
 +
The below bullets are additional background readings, books and study materials that can be used in the learning of TDD:
 +
* 5 min TDD overview video https://www.youtube.com/watch?v=QCif_-r8eK4
 +
* Graphical explanation of TDD http://www.agiledata.org/essays/tdd.html
 +
* Kent Beck book (he invented TDD) http://www.amazon.com/exec/obidos/ASIN/0321146530/
 +
* Astels TDD 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
 +
* JUnit Testing book - https://www.packtpub.com/application-development/testing-junit
 +
* Is TDD Dead? https://www.youtube.com/watch?v=z9quxZsLcfo
 +
* List of all open source testing tools - http://www.opensourcetesting.org/
 +
 +
 +
=== TDD Tutorials ===
 +
Below lists 3rd party tutorials, how-to's, and learning resources that explain TDD and JUnit. They may be useful as alternative or harder secondary learning activities so that students can dive in a bit deeper.
 +
* 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/
 +
** This is the tutorial used in the above activity, kept here for posterity sake.
 +
** 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 - it uses a helloworld example
 +
 +
* 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
 +
 +
* 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
 +
 +
* 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 "This material may NOT be used as course material without prior written agreement."
 +
  
=== Examples of OSS projects that use TDD ===
+
=== Examples of OSS projects that were implemented with TDD ===
 +
The below list shows actual open source projects that were created with TDD methodologies. These could be used as examples of TDD in-practice. Students could learn how TDD is done in real life, learn best practices, etc. They are divided below into the two best examples, and then a number of other weaker examples.
 
==== Best examples ====
 
==== Best examples ====
 
* http://junit.org/
 
* http://junit.org/
Line 167: Line 232:
  
  
=== 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
+
=== Initial Ideas and research ===
** Line-by-line explanation of code and tests and process to create Monopoly features via TDD
+
Below are a brainstorm of ideas that pre-empted the creation of the TDD learning activity. It is purely an idea and note taking set of bullets:
** 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."
+
 
+
 
+
 
+
=== 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 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
 
* Idea 2: Create a test harness to make, build, and run unit tests on an existing open source project
Line 206: Line 245:
 
** Iterating through tests once code has been written, helps to improve the tests
 
** Iterating through tests once code has been written, helps to improve the tests
  
* Dave thinks ManageIQ does unit testing
+
* Dave thinks ManageIQ community does unit testing
  
 
* Background reading:
 
* Background reading:
** http://www.cs.cofc.edu/~bowring/ - course in testing
+
** http://www.cs.cofc.edu/~bowring/ - Jim Bowring has a course in testing
 
** Boris Byser - the test guru
 
** Boris Byser - the test guru
 
** Kent Beck - extreme programming (ford motor)
 
** Kent Beck - extreme programming (ford motor)
** http://foss2serve.org/index.php/Test_Coverage_Activity
+
 
 +
[[Category: CS1]]
 +
[[Category: CS2]]
 +
[[Category: Good Draft]]

Revision as of 17:43, 8 March 2017

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 should be familiar with:
  • Programming simple Java
  • Developing object-oriented software (classes, methods, instances)
  • Test Driven Development (TDD) workflow and theory
Learning Objectives Upon completion, students should be able to:
  • Install and use 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

TDDEclipseJUnit.png


Background:

Is there background reading material?

It is assumed, as per the prerequisites above, that students have already learned about TDD. However, if teacher or students need some content to start on, the best quick dummies guide would be this YouTube video summarizing TDD, and this graphical explanation of the TDD process. If you want more extensive TDD learning content, check out Kent Beck's "Test-Driven Development by Example". He is the inventor of TDD and wrote JUnit, the focus of this exercise. Additionally, see how a CalPoly and College of Charleston class used TDD in their studies. For more resources, and ideas on secondary TDD exercises, see the Appendix of this page.

What is the rationale for this activity?

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 within particular constraints is an extension of quality assurance (QA) efforts that most professional software products enact to increase their products value. With TDD, this testing is built-in even before students 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 while implementing the TDD test code in Eclipse on your own computer. Finally, you will create standard functional code that gets the tests to succeed (green JUnit bar). You will hand in this code, the associated test code, and two screenshots.

Step 1: Setup Eclipse and JUnit

First, you will need to setup and understand your coding environment. If you have not setup the Eclipse IDE for java before, read through some of the below links. You need to be able to run code and tests with the IDE. There can be some unexpected "gotchas".

  • Download and install Eclipse - JUnit comes with "Eclipse IDE for Java Developers"
  • Become familiar with the Eclipse Workbench and in Running code - there is a built-in Eclipse Help Guide, as well as 3rd party tutorials.
  • If you get stuck on anything:
  • Start a new Java Project and include your own name in the 'Project name' field.
    • Ex: "NumberCounter-NYeates"


Step 2: Make the test

As per TDD you will write a failing test first, before writing any real code that achieves your purpose. The meat of this activity is in the Code Affine tutorial below:

  • 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 System Under Test (SUT) code (the code which implements the functionality that you actually want).
  • Create a file called "NumberRangeCounterTest.java" to put the test code into.
  • Create a separate file called "NumberRangeCounter.java" to put the skeleton SUT code into.
  • Implement the test class code and the skeleton SUT code found in the tutorial and get a failing test.
  • You will be marked up for commenting your code.
  • Take a screenshot of the failing test (red JUnit bar) and code.


Step 3: Write the code

You should now have a test case that fails and a stub/skeleton for the System Under Test (SUT) code. Now, you need to make the test succeed. This means implementing the SUT code (the code that actually implements the functionality wanted) to make the test go green in Eclipse.

  • Create working SUT code in the "NumberRangeCounter.java" file.
  • 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.


(Optional self-learning) For tips and tricks on using JUnit in Eclipse, see the following:


Deliverables:

After having gone through the above tutorials and coding exercise, students will hand in the following code and screenshots:

  • Test code and implementation (SUT) 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 SUT 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 SUT code that passes the (green) TDD test code Did not attempt - no screenshot, no code Attempted and SUT code exits, but was never able to get "Green" bar from JUnit SUT code exists and screenshot shows successful "Green" bar SUT code exists, screenshot shows successful "Green" bar, and comments have been added to the code

Comments:

What should the instructor know before using this activity?

  • Step through this activity yourself beforehand, as students will have some gotchas upon installing Eclipse and trying to use JUnit

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

  • Students may not be able to setup and start running code in Eclipse easily


Additional Information:

ACM Knowledge Area/Knowledge Unit SE - Software Engineering, from ACM_Body_of_Knowledge
ACM Topic SE/Testing types, SE/Testing Fundamentals, SE/Test-driven development - https://www.acm.org/education/CS2013-final-report.pdf
Level of Difficulty Medium
Estimated Time to Completion 2-6 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 operating systems 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.

  • Show students any unit testing or TDD-based development you may already have in place. A real life example, with an explanation from a community developer would be a perfect way to solidify the understanding that testing is necessary for real world software.



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



Appendix

The below appendix includes information found while researching and creating the above Learning Activity. Instructors may find it useful if they are wanting to create their own follow-on activities or want more info.


Background Reading

The below bullets are additional background readings, books and study materials that can be used in the learning of TDD:


TDD Tutorials

Below lists 3rd party tutorials, how-to's, and learning resources that explain TDD and JUnit. They may be useful as alternative or harder secondary learning activities so that students can dive in a bit deeper.

  • 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 "This material may NOT be used as course material without prior written agreement."


Examples of OSS projects that were implemented with TDD

The below list shows actual open source projects that were created with TDD methodologies. These could be used as examples of TDD in-practice. Students could learn how TDD is done in real life, learn best practices, etc. They are divided below into the two best examples, and then a number of other weaker examples.

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


Initial Ideas and research

Below are a brainstorm of ideas that pre-empted the creation of the TDD learning activity. It is purely an idea and note taking set of bullets:

  • 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 community does unit testing
  • Background reading:
Personal tools
Namespaces
Variants
Actions
Events
Learning Resources
HFOSS Projects
Evaluation
Navigation
Toolbox