SlideShare a Scribd company logo
1 of 17
Junit and Cactus

Dr. Himanshu Hora
SRMS College of Engineering & Technology
Bareilly (INDIA)
Table of Contents








Overview
Article Outline
Thesis
JUnit Background
Cactus Background
Pitfalls 1-6
Conclusion
Overview
 Junit and Cactus are popular tools for automating






testing of Java classes and web-based components
Automation accomplished using ANT (Java Make utility)
and often tested every time project built
These tools enable testers to “verify” the code is written
correctly – it was built right
Automated tests are very useful to show code works
correctly esp. after refactoring which is central to XP
I picked this article because deals with JUnit & Cactus,
offers a critique of the tools, and was practical, not just
theoretical
As this article describes, the tests themselves must be
built right in order to validate the code being tested
Outline
 Theme: Risk when testing with JUnit & Cactus
 Risk 1: No assert
 Risk 2: Unreasonable assert
 Risk 3: Console-Based Testing
 Risk 4: Unfocused Test Method
 Risk 5: Failure To Isolate Each Test
 Risk 6: Failure to Isolate Subject
Analysis
 Thesis: critique was correct but wordy, repetive, and






incomplete – missing some bigger pitfalls
Risk 1-3 are all the same – use assert correctly
Risk 4 is programming rule – write focused method
Risk 5 is JUnit rule – Use setUp and tearDown
Risk 6 is incomplete analysis of Cactus vs MockObj
Overview of Junit and Cactus, then discuss pitfalls, and
finally look at unmentioned pitfalls & issues
JUnit Overview
 Popular and simple Java framework / library for









automating testing
Integrates well with ANT – Java Make utility
General idea: write one test class per testee
Write one method to verify each main feature
Test class must extend TestCase and each test method
must start with “test”
Order of test method execution varies
Use assertTrue() and assertEquals() to verify code
Use setUp() & tearDown() prepare testcase testfixture
JUnit code example
Following test cases test the collection methods, isEmpty() and add()
import junit.framework.*;
public class SimpleTest extends TestCase {
private java.uti.Collection collection;
protected void setUp() { collection = new ArrayList(); } //
instantiates collection test fixture
protected void tearDown() { collection.clear(); }
public void testEmptyCollection() {
assertTrue(collection.isEmpty());
}
public void testOneItemCollection() {
collection.add("itemA");
assertEquals(1, collection.size());
}
}
Cactus Overview
 Built on Junit framework
 Intended to test JSP, Servlets, EJBs, Filters, and custom

tags
 Complex architecture that has client JVM call the J2EE
application server JVM via redirector
 Testcase classes must reside on client and server
 Adds two methods to Junit architecture, beginXX() and
endXX() which get called on client, rest on server
Cactus System Diagram
Cactus Sequence Diagram

– Jakarta website
Risk 1-3 – No assert, Unreasonable assert,
Console-Based Testing
 Risk 1-3 are all the same – use assert correctly
 Very important and author points out a major guideline
 test what is written in the javadocs for the testee
 implies javadocs must be up-to-date with requirements

 Author also points out to write a test case if encounter a

defect before it is corrected
 However, using assertTrue() and assertEquals() is
obvious
 These are the prominent features of the JUnit
Risk 4 – Unfocused Test Methods
 Writing focused tests is really just writing good code
 General rule of programming to make methods succinct,

this applies equally to test methods
 Writing focused test methods is the whole point
Risk 5 – Failure To Isolate Each
Test

Risk 5 is really saying to use setUp() and tearDown() to prepare/release test
fixture, an obvious suggestion – example from JUnit site
Bigger pitfall is automating creation of the test fixture in distributed
environments
import junit.framework.*;
public class SimpleTest extends TestCase {
private java.uti.Collection collection;
protected void setUp() { collection = new ArrayList(); } // instantiates
collection test fixture for 2 tests
protected void tearDown() { collection.clear(); }
public void testEmptyCollection() {
assertTrue(collection.isEmpty());
}
public void testOneItemCollection() {
collection.add("itemA");
assertEquals(1, collection.size());
}
}
Risk 6 – Failure to Isolate Subject
 Author points out one drawback of Cactus is that does

not isolate test case as MockObjects does
 MockObjects simulates the Servlet container
 Mock Object framework does isolate test but at big expense

 Massive amount of stubs needed, more code to maintain

 While Cactus may be better than MockObjects, it may

NOT be better than HttpUnit, why not compare these?
Alternative tools
 HttpUnit cleaner, simpler tool than Cactus
 HttpUnit is black box testing by calling webserver
 Test code resides ONLY on client JVM

 Various interfaces like JWebUnit (Java API) and





WebTest (XML) integrate well with ANT
Use Junit for unit tests and HttpUnit for functional
Features to analyze HTML, ie. table element tests
Features to input HTML form elements
http://www.junit.org/news/extension/index.htm
Conclusion
 Article lists some useful guidelines & pitfalls in an wordy fashion
 Many pitfalls were obvious and important ones not mentioned
 Important pitfalls not mentioned include







Cost, complexity, difficulty of distributed tests not mentioned
Performs white box tests, yet, JUnit already does this
Does not test HTTP interface (tests presentation layer poorly)
Test code must reside in same package as testee & both JVMs
Testers must be programmers
JWebUnit & WebTest better for web unit testing

 At times unclear when addressing Junit vs. Cactus and unnecessarily
complex coding examples
 However, automating testing can save time and money in the long run
 These tools, while not perfect, are major players for automated Java
testing and can verify functionality during development and refactoring
THANK YOU
Dr. Himanshu Hora
SRMS College of Engineering & Technology
Bareilly (INDIA)

More Related Content

What's hot

Boosting Approach to Solving Machine Learning Problems
Boosting Approach to Solving Machine Learning ProblemsBoosting Approach to Solving Machine Learning Problems
Boosting Approach to Solving Machine Learning ProblemsDr Sulaimon Afolabi
 
Processor allocation in Distributed Systems
Processor allocation in Distributed SystemsProcessor allocation in Distributed Systems
Processor allocation in Distributed SystemsRitu Ranjan Shrivastwa
 
Machine learning ppt.
Machine learning ppt.Machine learning ppt.
Machine learning ppt.ASHOK KUMAR
 
Swarm intelligence
Swarm intelligenceSwarm intelligence
Swarm intelligenceSophia
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computingjayavignesh86
 
Neural Networks for Pattern Recognition
Neural Networks for Pattern RecognitionNeural Networks for Pattern Recognition
Neural Networks for Pattern RecognitionVipra Singh
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- IntroductionDebasis Das
 
Microkernel architecture
Microkernel architecture Microkernel architecture
Microkernel architecture RQK Khan
 
User Interface Analysis and Design
User Interface Analysis and DesignUser Interface Analysis and Design
User Interface Analysis and Design Saqib Raza
 
REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1Embeddedcraft Craft
 
Centralized shared memory architectures
Centralized shared memory architecturesCentralized shared memory architectures
Centralized shared memory architecturesGokuldhev mony
 

What's hot (20)

Boosting Approach to Solving Machine Learning Problems
Boosting Approach to Solving Machine Learning ProblemsBoosting Approach to Solving Machine Learning Problems
Boosting Approach to Solving Machine Learning Problems
 
Processor allocation in Distributed Systems
Processor allocation in Distributed SystemsProcessor allocation in Distributed Systems
Processor allocation in Distributed Systems
 
SWARM INTELLIGENCE
SWARM INTELLIGENCESWARM INTELLIGENCE
SWARM INTELLIGENCE
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Machine learning ppt.
Machine learning ppt.Machine learning ppt.
Machine learning ppt.
 
Soft computing
Soft computing Soft computing
Soft computing
 
Swarm intelligence
Swarm intelligenceSwarm intelligence
Swarm intelligence
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
 
Neural Networks for Pattern Recognition
Neural Networks for Pattern RecognitionNeural Networks for Pattern Recognition
Neural Networks for Pattern Recognition
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 
Basics of Soft Computing
Basics of Soft  Computing Basics of Soft  Computing
Basics of Soft Computing
 
Microkernel architecture
Microkernel architecture Microkernel architecture
Microkernel architecture
 
User Interface Analysis and Design
User Interface Analysis and DesignUser Interface Analysis and Design
User Interface Analysis and Design
 
REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
 
convex hull
convex hullconvex hull
convex hull
 
RTOS Basic Concepts
RTOS Basic ConceptsRTOS Basic Concepts
RTOS Basic Concepts
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Measures of query cost
Measures of query costMeasures of query cost
Measures of query cost
 
Centralized shared memory architectures
Centralized shared memory architecturesCentralized shared memory architectures
Centralized shared memory architectures
 

Similar to Junit and cactus

Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in JavaMichael Fons
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentationSanjib Dhar
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Comunidade NetPonto
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest modulePyCon Italia
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightOpenDaylight
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Hong Le Van
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosFlutter Agency
 
Apache Ant
Apache AntApache Ant
Apache AntAli Bahu
 

Similar to Junit and cactus (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Google test training
Google test trainingGoogle test training
Google test training
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Apache Ant
Apache AntApache Ant
Apache Ant
 

More from Himanshu

Structural patterns
Structural patternsStructural patterns
Structural patternsHimanshu
 
Software product line
Software product lineSoftware product line
Software product lineHimanshu
 
Shared information systems
Shared information systemsShared information systems
Shared information systemsHimanshu
 
Design Pattern
Design PatternDesign Pattern
Design PatternHimanshu
 
Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
Architecture Review
Architecture ReviewArchitecture Review
Architecture ReviewHimanshu
 
Reliability and its principals
Reliability and its principalsReliability and its principals
Reliability and its principalsHimanshu
 
Structural and functional testing
Structural and functional testingStructural and functional testing
Structural and functional testingHimanshu
 
White box black box & gray box testing
White box black box & gray box testingWhite box black box & gray box testing
White box black box & gray box testingHimanshu
 
Pareto analysis
Pareto analysisPareto analysis
Pareto analysisHimanshu
 
Load runner & win runner
Load runner & win runnerLoad runner & win runner
Load runner & win runnerHimanshu
 
Crud and jad
Crud and jadCrud and jad
Crud and jadHimanshu
 
Risk based testing and random testing
Risk based testing and random testingRisk based testing and random testing
Risk based testing and random testingHimanshu
 
Testing a data warehouses
Testing a data warehousesTesting a data warehouses
Testing a data warehousesHimanshu
 
Software testing tools and its taxonomy
Software testing tools and its taxonomySoftware testing tools and its taxonomy
Software testing tools and its taxonomyHimanshu
 
Software reliability engineering process
Software reliability engineering processSoftware reliability engineering process
Software reliability engineering processHimanshu
 
Software reliability growth model
Software reliability growth modelSoftware reliability growth model
Software reliability growth modelHimanshu
 
Software reliability tools and common software errors
Software reliability tools and common software errorsSoftware reliability tools and common software errors
Software reliability tools and common software errorsHimanshu
 
Regression and performance testing
Regression and performance testingRegression and performance testing
Regression and performance testingHimanshu
 

More from Himanshu (20)

Structural patterns
Structural patternsStructural patterns
Structural patterns
 
Software product line
Software product lineSoftware product line
Software product line
 
Shared information systems
Shared information systemsShared information systems
Shared information systems
 
Saam
SaamSaam
Saam
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Architecture Review
Architecture ReviewArchitecture Review
Architecture Review
 
Reliability and its principals
Reliability and its principalsReliability and its principals
Reliability and its principals
 
Structural and functional testing
Structural and functional testingStructural and functional testing
Structural and functional testing
 
White box black box & gray box testing
White box black box & gray box testingWhite box black box & gray box testing
White box black box & gray box testing
 
Pareto analysis
Pareto analysisPareto analysis
Pareto analysis
 
Load runner & win runner
Load runner & win runnerLoad runner & win runner
Load runner & win runner
 
Crud and jad
Crud and jadCrud and jad
Crud and jad
 
Risk based testing and random testing
Risk based testing and random testingRisk based testing and random testing
Risk based testing and random testing
 
Testing a data warehouses
Testing a data warehousesTesting a data warehouses
Testing a data warehouses
 
Software testing tools and its taxonomy
Software testing tools and its taxonomySoftware testing tools and its taxonomy
Software testing tools and its taxonomy
 
Software reliability engineering process
Software reliability engineering processSoftware reliability engineering process
Software reliability engineering process
 
Software reliability growth model
Software reliability growth modelSoftware reliability growth model
Software reliability growth model
 
Software reliability tools and common software errors
Software reliability tools and common software errorsSoftware reliability tools and common software errors
Software reliability tools and common software errors
 
Regression and performance testing
Regression and performance testingRegression and performance testing
Regression and performance testing
 

Recently uploaded

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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)
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Junit and cactus

  • 1. Junit and Cactus Dr. Himanshu Hora SRMS College of Engineering & Technology Bareilly (INDIA)
  • 2. Table of Contents        Overview Article Outline Thesis JUnit Background Cactus Background Pitfalls 1-6 Conclusion
  • 3. Overview  Junit and Cactus are popular tools for automating      testing of Java classes and web-based components Automation accomplished using ANT (Java Make utility) and often tested every time project built These tools enable testers to “verify” the code is written correctly – it was built right Automated tests are very useful to show code works correctly esp. after refactoring which is central to XP I picked this article because deals with JUnit & Cactus, offers a critique of the tools, and was practical, not just theoretical As this article describes, the tests themselves must be built right in order to validate the code being tested
  • 4. Outline  Theme: Risk when testing with JUnit & Cactus  Risk 1: No assert  Risk 2: Unreasonable assert  Risk 3: Console-Based Testing  Risk 4: Unfocused Test Method  Risk 5: Failure To Isolate Each Test  Risk 6: Failure to Isolate Subject
  • 5. Analysis  Thesis: critique was correct but wordy, repetive, and      incomplete – missing some bigger pitfalls Risk 1-3 are all the same – use assert correctly Risk 4 is programming rule – write focused method Risk 5 is JUnit rule – Use setUp and tearDown Risk 6 is incomplete analysis of Cactus vs MockObj Overview of Junit and Cactus, then discuss pitfalls, and finally look at unmentioned pitfalls & issues
  • 6. JUnit Overview  Popular and simple Java framework / library for        automating testing Integrates well with ANT – Java Make utility General idea: write one test class per testee Write one method to verify each main feature Test class must extend TestCase and each test method must start with “test” Order of test method execution varies Use assertTrue() and assertEquals() to verify code Use setUp() & tearDown() prepare testcase testfixture
  • 7. JUnit code example Following test cases test the collection methods, isEmpty() and add() import junit.framework.*; public class SimpleTest extends TestCase { private java.uti.Collection collection; protected void setUp() { collection = new ArrayList(); } // instantiates collection test fixture protected void tearDown() { collection.clear(); } public void testEmptyCollection() { assertTrue(collection.isEmpty()); } public void testOneItemCollection() { collection.add("itemA"); assertEquals(1, collection.size()); } }
  • 8. Cactus Overview  Built on Junit framework  Intended to test JSP, Servlets, EJBs, Filters, and custom tags  Complex architecture that has client JVM call the J2EE application server JVM via redirector  Testcase classes must reside on client and server  Adds two methods to Junit architecture, beginXX() and endXX() which get called on client, rest on server
  • 10. Cactus Sequence Diagram – Jakarta website
  • 11. Risk 1-3 – No assert, Unreasonable assert, Console-Based Testing  Risk 1-3 are all the same – use assert correctly  Very important and author points out a major guideline  test what is written in the javadocs for the testee  implies javadocs must be up-to-date with requirements  Author also points out to write a test case if encounter a defect before it is corrected  However, using assertTrue() and assertEquals() is obvious  These are the prominent features of the JUnit
  • 12. Risk 4 – Unfocused Test Methods  Writing focused tests is really just writing good code  General rule of programming to make methods succinct, this applies equally to test methods  Writing focused test methods is the whole point
  • 13. Risk 5 – Failure To Isolate Each Test Risk 5 is really saying to use setUp() and tearDown() to prepare/release test fixture, an obvious suggestion – example from JUnit site Bigger pitfall is automating creation of the test fixture in distributed environments import junit.framework.*; public class SimpleTest extends TestCase { private java.uti.Collection collection; protected void setUp() { collection = new ArrayList(); } // instantiates collection test fixture for 2 tests protected void tearDown() { collection.clear(); } public void testEmptyCollection() { assertTrue(collection.isEmpty()); } public void testOneItemCollection() { collection.add("itemA"); assertEquals(1, collection.size()); } }
  • 14. Risk 6 – Failure to Isolate Subject  Author points out one drawback of Cactus is that does not isolate test case as MockObjects does  MockObjects simulates the Servlet container  Mock Object framework does isolate test but at big expense  Massive amount of stubs needed, more code to maintain  While Cactus may be better than MockObjects, it may NOT be better than HttpUnit, why not compare these?
  • 15. Alternative tools  HttpUnit cleaner, simpler tool than Cactus  HttpUnit is black box testing by calling webserver  Test code resides ONLY on client JVM  Various interfaces like JWebUnit (Java API) and     WebTest (XML) integrate well with ANT Use Junit for unit tests and HttpUnit for functional Features to analyze HTML, ie. table element tests Features to input HTML form elements http://www.junit.org/news/extension/index.htm
  • 16. Conclusion  Article lists some useful guidelines & pitfalls in an wordy fashion  Many pitfalls were obvious and important ones not mentioned  Important pitfalls not mentioned include       Cost, complexity, difficulty of distributed tests not mentioned Performs white box tests, yet, JUnit already does this Does not test HTTP interface (tests presentation layer poorly) Test code must reside in same package as testee & both JVMs Testers must be programmers JWebUnit & WebTest better for web unit testing  At times unclear when addressing Junit vs. Cactus and unnecessarily complex coding examples  However, automating testing can save time and money in the long run  These tools, while not perfect, are major players for automated Java testing and can verify functionality during development and refactoring
  • 17. THANK YOU Dr. Himanshu Hora SRMS College of Engineering & Technology Bareilly (INDIA)