SlideShare a Scribd company logo
1 of 32
New Features of Test::Unit 2.0 Daniel Berger Ruby, C, Perl Win32Utils SysUtils Shards Sapphire
Test::Unit now a gem ,[object Object],[object Object]
I Do Not Know ,[object Object],[object Object],[object Object],[object Object]
How to use Test::Unit 2.x ,[object Object],[object Object],[object Object]
New Assertions ,[object Object],[object Object],[object Object]
assert_true assert_true(condition) Same as: assert_equal(true, condition) assert(condition)
assert_false assert_false(condition) Same as: assert_equal(false, condition)
assert_boolean assert_boolean(result) Same as: assert_equal(true, [true, false].include?(result))
Wow Ooh, aah.
New stuff to use within tests ,[object Object],[object Object],[object Object],[object Object],[object Object]
omit, omit_if, omit_unless Used to skip tests entirely Or in specific circumstances
Omit Examples class TC_MyTest < Test::Unit::TestCase def test_alpha omit(&quot;Buggy library. Skip&quot;) # never reach past here assert_true(1 == 1) end def test_beta omit_if(File::ALT_SEPARATOR, &quot;Skipping test on MS Windows&quot;) # Won’t run this test on MS Windows (or VMS) assert_true(1 == 1) end def test_gamma omit_unless(File::ALT_SEPARATOR, &quot;Only run on MS Windows&quot;) # Won’t run this test except on MS Windows assert_true(1 == 1) end end
Output 1) Omission: Buggy library. Skip test_alpha(TC_MyTest) omit_examples.rb:7:in `test_alpha' 2) Omission: Skipping test on MS Windows test_beta(TC_MyTest) omit_examples.rb:12:in `test_beta' 3 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 2 omissions, 0 notifications Only 1 assertion ran, the other two were skipped
pend ,[object Object],[object Object]
pend example class TC_MyTest < Test::Unit::TestCase def setup @obj = MyClass.new end def test_alpha pend(&quot;The 'alpha' function hasn't been implemented yet&quot;) assert_true(@obj.alpha) end end 1) Pending: The 'alpha' function hasn't been implemented yet test_alpha(TC_MyTest) pend_example.rb:13:in `test_alpha' 1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, 0 omissions, 0 notifications
notify ,[object Object],[object Object],[object Object]
notify example class TC_MyTest < Test::Unit::TestCase def test_alpha notify(&quot;starting the alpha test&quot;) assert_true(1 == 1) notify(&quot;finished the alpha test&quot;) end end 1) Notification: starting the alpha test test_alpha(TC_MyTest) notify_example.rb:7:in `test_alpha' 2) Notification: finished the alpha test test_alpha(TC_MyTest) notify_example.rb:9:in `test_alpha' 1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 2 notifications
startup and shutdown ,[object Object],[object Object],[object Object],[object Object]
startup & shutdown example class TC_MyTest < Test::Unit::TestCase def self.startup @@file_name = File.join(Dir.pwd, 'my_test_file.txt') @@file_handle = File.open(@@file_name, 'w') end def test_file_path assert_respond_to(@@file_handle, :path) end def self.shutdown @@file_handle.close File.delete(@@file_name) end end Don’t forget the ‘self’
multiple setup & teardown ,[object Object],[object Object],[object Object],[object Object]
multiple setups class TC_MyTest < Test::Unit::TestCase def setup  # first @standard = MyClass.new end setup # second def setup_alpha @alpha = MyClass.new end setup # third def setup_beta @beta = MyClass.new end def test_stuff assert_true(1 == 1) end end
multiple teardowns class TC_MyTest < Test::Unit::TestCase def test_stuff assert_true(1 == 1) end def teardown  # last @standard = nil end teardown # second def teardown_alpha @alpha = nil end teardown # first def teardown_beta @beta = nil end end
Setup Attributes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Attribute ‘before’ class TC_MyTest < Test::Unit::TestCase def setup #  Third puts &quot;In setup&quot; end setup #  Fourth def setup_alpha puts &quot;In setup_alpha&quot; end setup :before => :prepend #  First def setup_beta puts &quot;In setup_beta&quot; end setup :before => :append #  Second def setup_gamma puts &quot;In setup_gamma&quot; end end
Quick Rules Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Better Diff Output 1) Failure: test_string_diff(TC_MyTest) [diff_example.rb:7]: <&quot;weird&quot;> expected but was <&quot;wierd&quot;>. 1) Failure: test_string_diff(TC_MyTest) [diff_example.rb:7]: <&quot;weird&quot;> expected but was <&quot;wierd&quot;>. diff: - weird ?  - + wierd ?  + Old: New:
Priority Mode ,[object Object],[object Object],[object Object],[object Object],[object Object]
Sample Priority Output 1) Failure: test_one(TC_MyTest) [priority.rb:47]: <true> expected but was <false> 2) Failure: test_two(TC_MyTest) [priority.rb:51]: <true> expected but was <false> 7 tests, 7 assertions, 2 failures , 0 errors, 0 pendings, 0 omissions, 0 notifications 1) Failure: test_one(TC_MyTest) [priority.rb:47]: <true> expected but was <false> 2) Failure: test_two(TC_MyTest) [priority.rb:51]: <true> expected but was <false> 6 tests, 6 assertions, 2 failures , 0 errors, 0 pendings, 0 omissions, 0 notifications
Forcing a test priority :must def test_blah assert_true(1 == 1) end This test will always run, regardless of the “–priority-mode” switch.
Priority Modes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Colorized Output ,[object Object],[object Object],[object Object]
Any questions?

More Related Content

What's hot

Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnitinTwentyEight Minutes
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with JunitValerio Maggio
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesNarendra Pathai
 
05 junit
05 junit05 junit
05 junitmha4
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Kiki Ahmadi
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaRavikiran J
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 

What's hot (20)

Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnit
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Unit test
Unit testUnit test
Unit test
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
Junit
JunitJunit
Junit
 
05 junit
05 junit05 junit
05 junit
 
J Unit
J UnitJ Unit
J Unit
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
3 j unit
3 j unit3 j unit
3 j unit
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 

Viewers also liked

Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpecNascenia IT
 
Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Vysakh Sreenivasan
 
RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試Wen-Tien Chang
 
SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...
SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...
SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...Louis Göhl
 

Viewers also liked (8)

Basic RSpec 2
Basic RSpec 2Basic RSpec 2
Basic RSpec 2
 
Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpec
 
MacRuby
MacRubyMacRuby
MacRuby
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)
 
RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試
 
SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...
SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...
SIA311 Better Together: Microsoft Exchange Server 2010 and Microsoft Forefron...
 
RSpec 2 Best practices
RSpec 2 Best practicesRSpec 2 Best practices
RSpec 2 Best practices
 

Similar to New Features Of Test Unit 2.x

YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Criticjoshua.mcadams
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, PloneQuintagroup
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Frameworkwebhostingguy
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style GuideJacky Lai
 
Software Testing
Software TestingSoftware Testing
Software TestingLambert Lum
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::ClassCurtis Poe
 
Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slidesericholscher
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
YAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl CriticYAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl Criticjoshua.mcadams
 
White paper for unit testing using boost
White paper for unit testing using boostWhite paper for unit testing using boost
White paper for unit testing using boostnkkatiyar
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
Testing And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionTesting And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionDenard Springle IV
 

Similar to New Features Of Test Unit 2.x (20)

YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Critic
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
 
Test Driven
Test DrivenTest Driven
Test Driven
 
Unit testing
Unit testingUnit testing
Unit testing
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::Class
 
Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slides
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
Php tests tips
Php tests tipsPhp tests tips
Php tests tips
 
YAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl CriticYAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl Critic
 
White paper for unit testing using boost
White paper for unit testing using boostWhite paper for unit testing using boost
White paper for unit testing using boost
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Testing And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionTesting And Mxunit In ColdFusion
Testing And Mxunit In ColdFusion
 
Deixe o teste infectar você
Deixe o teste infectar vocêDeixe o teste infectar você
Deixe o teste infectar você
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 

Recently uploaded

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

New Features Of Test Unit 2.x

  • 1. New Features of Test::Unit 2.0 Daniel Berger Ruby, C, Perl Win32Utils SysUtils Shards Sapphire
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. assert_true assert_true(condition) Same as: assert_equal(true, condition) assert(condition)
  • 7. assert_false assert_false(condition) Same as: assert_equal(false, condition)
  • 8. assert_boolean assert_boolean(result) Same as: assert_equal(true, [true, false].include?(result))
  • 10.
  • 11. omit, omit_if, omit_unless Used to skip tests entirely Or in specific circumstances
  • 12. Omit Examples class TC_MyTest < Test::Unit::TestCase def test_alpha omit(&quot;Buggy library. Skip&quot;) # never reach past here assert_true(1 == 1) end def test_beta omit_if(File::ALT_SEPARATOR, &quot;Skipping test on MS Windows&quot;) # Won’t run this test on MS Windows (or VMS) assert_true(1 == 1) end def test_gamma omit_unless(File::ALT_SEPARATOR, &quot;Only run on MS Windows&quot;) # Won’t run this test except on MS Windows assert_true(1 == 1) end end
  • 13. Output 1) Omission: Buggy library. Skip test_alpha(TC_MyTest) omit_examples.rb:7:in `test_alpha' 2) Omission: Skipping test on MS Windows test_beta(TC_MyTest) omit_examples.rb:12:in `test_beta' 3 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 2 omissions, 0 notifications Only 1 assertion ran, the other two were skipped
  • 14.
  • 15. pend example class TC_MyTest < Test::Unit::TestCase def setup @obj = MyClass.new end def test_alpha pend(&quot;The 'alpha' function hasn't been implemented yet&quot;) assert_true(@obj.alpha) end end 1) Pending: The 'alpha' function hasn't been implemented yet test_alpha(TC_MyTest) pend_example.rb:13:in `test_alpha' 1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, 0 omissions, 0 notifications
  • 16.
  • 17. notify example class TC_MyTest < Test::Unit::TestCase def test_alpha notify(&quot;starting the alpha test&quot;) assert_true(1 == 1) notify(&quot;finished the alpha test&quot;) end end 1) Notification: starting the alpha test test_alpha(TC_MyTest) notify_example.rb:7:in `test_alpha' 2) Notification: finished the alpha test test_alpha(TC_MyTest) notify_example.rb:9:in `test_alpha' 1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 2 notifications
  • 18.
  • 19. startup & shutdown example class TC_MyTest < Test::Unit::TestCase def self.startup @@file_name = File.join(Dir.pwd, 'my_test_file.txt') @@file_handle = File.open(@@file_name, 'w') end def test_file_path assert_respond_to(@@file_handle, :path) end def self.shutdown @@file_handle.close File.delete(@@file_name) end end Don’t forget the ‘self’
  • 20.
  • 21. multiple setups class TC_MyTest < Test::Unit::TestCase def setup # first @standard = MyClass.new end setup # second def setup_alpha @alpha = MyClass.new end setup # third def setup_beta @beta = MyClass.new end def test_stuff assert_true(1 == 1) end end
  • 22. multiple teardowns class TC_MyTest < Test::Unit::TestCase def test_stuff assert_true(1 == 1) end def teardown # last @standard = nil end teardown # second def teardown_alpha @alpha = nil end teardown # first def teardown_beta @beta = nil end end
  • 23.
  • 24. Attribute ‘before’ class TC_MyTest < Test::Unit::TestCase def setup # Third puts &quot;In setup&quot; end setup # Fourth def setup_alpha puts &quot;In setup_alpha&quot; end setup :before => :prepend # First def setup_beta puts &quot;In setup_beta&quot; end setup :before => :append # Second def setup_gamma puts &quot;In setup_gamma&quot; end end
  • 25.
  • 26. Better Diff Output 1) Failure: test_string_diff(TC_MyTest) [diff_example.rb:7]: <&quot;weird&quot;> expected but was <&quot;wierd&quot;>. 1) Failure: test_string_diff(TC_MyTest) [diff_example.rb:7]: <&quot;weird&quot;> expected but was <&quot;wierd&quot;>. diff: - weird ? - + wierd ? + Old: New:
  • 27.
  • 28. Sample Priority Output 1) Failure: test_one(TC_MyTest) [priority.rb:47]: <true> expected but was <false> 2) Failure: test_two(TC_MyTest) [priority.rb:51]: <true> expected but was <false> 7 tests, 7 assertions, 2 failures , 0 errors, 0 pendings, 0 omissions, 0 notifications 1) Failure: test_one(TC_MyTest) [priority.rb:47]: <true> expected but was <false> 2) Failure: test_two(TC_MyTest) [priority.rb:51]: <true> expected but was <false> 6 tests, 6 assertions, 2 failures , 0 errors, 0 pendings, 0 omissions, 0 notifications
  • 29. Forcing a test priority :must def test_blah assert_true(1 == 1) end This test will always run, regardless of the “–priority-mode” switch.
  • 30.
  • 31.