SlideShare a Scribd company logo
1 of 27
Download to read offline
Unit Testing with WOUnit
Henrique Prange (HP)
• WOUnittest
• Wonder’s ERXTestCase
• JavaMemoryAdaptor
• Ad hoc Testing
History
Why another framework?
• Simple
• Fast
• Full support for Wonder features
• Concise assertions
• Test isolation
Features
• Use the new @Rule
• MockEditingContext extends ERXEditingContext
• Useful assertions for EOF logic
• Compatible with WOUnittest
Writing Tests
• MockEditingContext annotated with @Rule
• Load the required EOModels before running tests
• Clear the environment after running each test
• Prepare EOs
• Play with EOs
• Use assertions to verify behavior
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@Test
public void cantSaveFooWithNullProperty() {
Foo foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class);
foo.setProperty(null);
confirm(foo, cannotBeSavedBecause("Foo must have a property"));
}
}
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@Test
public void cantSaveFooWithNullProperty() {
Foo foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class);
foo.setProperty(null);
confirm(foo, cannotBeSavedBecause("Foo must have a property"));
}
@Test
public void canSaveFooWithNotNullProperty() {
Foo foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class);
foo.setProperty("bar");
confirm(foo, canBeSaved());
}
}
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
private Foo foo;
@Before
public void setup() {
foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class);
}
@Test
public void cantSaveFooWithNullProperty() {
foo.setProperty(null);
confirm(foo, cannotBeSavedBecause("Foo must have a property"));
}
@Test
public void canSaveFooWithNotNullProperty() {
foo.setProperty("bar");
confirm(foo, canBeSaved());
}
}
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@UnderTest
private Foo foo;
@Test
public void cantSaveFooWithNullProperty() {
foo.setProperty(null);
confirm(foo, cannotBeSavedBecause("Foo must have a property"));
}
@Test
public void canSaveFooWithNotNullProperty() {
foo.setProperty("bar");
confirm(foo, canBeSaved());
}
}
@UnderTest
• Behave as a real object
• All validations apply
• Alternative to createAndInsertObject
Assertions
• EOAssert class
• EO can/cannot be saved
• EO can/cannot be deleted
• EO has/hasn’t been saved
• EO has/hasn’t been deleted
• EC does/doesn’t save changes successfully
http://theinspirationroom.com
Dummy Objects
• Do not need to be initialized
• Because validations don’t apply
• @Dummy as alternative to ec.createSavedObject
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@UnderTest
private Foo foo;
@Test
public void canSaveFooWithBar() {
Bar bar = ec.createSavedObject(Bar.class);
foo.setBar(bar);
confirm(foo, canBeSaved());
}
}
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@UnderTest
private Foo foo;
@Dummy
private Bar bar;
@Test
public void canSaveFooWithBar() {
foo.setBar(bar);
confirm(foo, canBeSaved());
}
}
NSArray of EOs
• Useful to test toMany relationships
• Work with @UnderTest and @Dummy
• EOs can be spied with @Spy
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@UnderTest
private Foo foo;
@Dummy
private Bar bar1, bar2, bar3, bar4;
@Test
public void cannotSaveFooWithLessThanFiveBars() {
foo.addToBarRelationship(bar1);
foo.addToBarRelationship(bar2);
foo.addToBarRelationship(bar3);
foo.addToBarRelationship(bar4);
confirm(foo, cannotBeSaved());
}
}
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@UnderTest
private Foo foo;
@Dummy(size = 4)
private NSArray<Bar> bars;
@Test
public void cannotSaveFooWithLessThanFiveBars() {
foo.addObjectsToBothSidesOfRelationshipWithKey(bars, Foo.BARS_KEY);
confirm(foo, cannotBeSaved());
}
}
Restrictions
• No support for Properties
• No support for Localization
• No support for SQL operations
http://www.wikipedia.org
Spying Objects
• Useful to workaround WOUnit limitations
• Allows to change and verify behavior
• Requires Mockito
• @Spy as alternative to spy(new Foo) + insertObject
• Requires @RunWith(MockitoJUnitRunner.class)
Sample
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@Test
public void callSlowMethodWhenDoingSomething() {
Foo foo = new Foo();
foo = Mockito.spy(foo);
ec.insertObject(foo);
Mockito.doNothing().when(foo).slowMethodWithSideEffects();
foo.doSomething();
Mockito.verify(foo).slowMethodWithSideEffects();
}
}
Sample
@RunWith(MockitoJUnitRunner.class)
class FooTest {
@Rule
public MockEditingContext ec = new MockEditingContext("MyModel");
@Spy @UnderTest
private Foo foo;
@Test
public void callSlowMethodWhenDoingSomething() {
Mockito.doNothing().when(foo).slowMethodWithSideEffects();
foo.doSomething();
Mockito.verify(foo).slowMethodWithSideEffects();
}
}
DEMO
Future
• Improved troubleshooting messaging
• Automatically load EOModels
• Fix for issue #20
License and Distribution
• It’s free
• Apache 2 license
• Source and Binaries
• hprange.github.com/wounit
• github.com/hprange/wounit
• maven.wocommunity.org
Q&A
Henrique Prange (HP)
hprange@gmail.com
twitter.com/hprange

More Related Content

What's hot

Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
How to get full power from WebApi
How to get full power from WebApiHow to get full power from WebApi
How to get full power from WebApiRaffaele Rialdi
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)jeresig
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patternsAlex Theedom
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011Alexander Klimetschek
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsEffie Arditi
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScriptLilia Sfaxi
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Antonio Peric-Mazar
 
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGMarakana Inc.
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React AppAll Things Open
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
02 beginning code first
02   beginning code first02   beginning code first
02 beginning code firstMaxim Shaptala
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design PatternsAlex Theedom
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSShekhar Gulati
 
Scaladays 2014 introduction to scalatest selenium dsl
Scaladays 2014   introduction to scalatest selenium dslScaladays 2014   introduction to scalatest selenium dsl
Scaladays 2014 introduction to scalatest selenium dslMatthew Farwell
 
Unsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST APIUnsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST APIMikhail Egorov
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium Zoe Gilbert
 

What's hot (20)

Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
How to get full power from WebApi
How to get full power from WebApiHow to get full power from WebApi
How to get full power from WebApi
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
 
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUG
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Foundation selenium java
Foundation selenium java Foundation selenium java
Foundation selenium java
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
02 beginning code first
02   beginning code first02   beginning code first
02 beginning code first
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
Scaladays 2014 introduction to scalatest selenium dsl
Scaladays 2014   introduction to scalatest selenium dslScaladays 2014   introduction to scalatest selenium dsl
Scaladays 2014 introduction to scalatest selenium dsl
 
Unsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST APIUnsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST API
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 

Viewers also liked

Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to WonderWO Community
 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache CayenneWO Community
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSWO Community
 
Build and deployment
Build and deploymentBuild and deployment
Build and deploymentWO Community
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsWO Community
 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldWO Community
 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W WO Community
 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on WindowsWO Community
 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" patternWO Community
 

Viewers also liked (15)

Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to Wonder
 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
 
iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWS
 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
 
WOver
WOverWOver
WOver
 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W
 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
 
High availability
High availabilityHigh availability
High availability
 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
 

Similar to Unit Testing with WOUnit

More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)Jen Wong
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksWO Community
 
Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project WonderWO Community
 
Persistent Session Storage
Persistent Session StoragePersistent Session Storage
Persistent Session StorageWO Community
 
JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainersSunghyouk Bae
 
Custom EOAdaptors and ERSolr
Custom EOAdaptors and ERSolrCustom EOAdaptors and ERSolr
Custom EOAdaptors and ERSolrWO Community
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST serviceWO Community
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworksTomáš Kypta
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014FalafelSoftware
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best PracticesJitendra Zaa
 
Testing – With Mock Objects
Testing – With Mock ObjectsTesting – With Mock Objects
Testing – With Mock Objectsemmettwalsh
 
J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드ksain
 
Testing the waters of iOS
Testing the waters of iOSTesting the waters of iOS
Testing the waters of iOSKremizas Kostas
 

Similar to Unit Testing with WOUnit (20)

ERRest and Dojo
ERRest and DojoERRest and Dojo
ERRest and Dojo
 
ERRest
ERRestERRest
ERRest
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
ERRest in Depth
ERRest in DepthERRest in Depth
ERRest in Depth
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
 
Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
 
Persistent Session Storage
Persistent Session StoragePersistent Session Storage
Persistent Session Storage
 
JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainers
 
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
 
Custom EOAdaptors and ERSolr
Custom EOAdaptors and ERSolrCustom EOAdaptors and ERSolr
Custom EOAdaptors and ERSolr
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST service
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworks
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
Testing – With Mock Objects
Testing – With Mock ObjectsTesting – With Mock Objects
Testing – With Mock Objects
 
J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드
 
Testing the waters of iOS
Testing the waters of iOSTesting the waters of iOS
Testing the waters of iOS
 
Spock
SpockSpock
Spock
 

More from WO Community

Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languagesWO Community
 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerWO Community
 
CMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanCMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanWO Community
 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects OptimizationWO Community
 
ERRest: the Basics
ERRest: the BasicsERRest: the Basics
ERRest: the BasicsWO Community
 

More from WO Community (11)

Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languages
 
WOdka
WOdkaWOdka
WOdka
 
ERGroupware
ERGroupwareERGroupware
ERGroupware
 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRoller
 
CMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanCMS / BLOG and SnoWOman
CMS / BLOG and SnoWOman
 
Using GIT
Using GITUsing GIT
Using GIT
 
Back2 future
Back2 futureBack2 future
Back2 future
 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects Optimization
 
Dynamic Elements
Dynamic ElementsDynamic Elements
Dynamic Elements
 
Practical ERSync
Practical ERSyncPractical ERSync
Practical ERSync
 
ERRest: the Basics
ERRest: the BasicsERRest: the Basics
ERRest: the Basics
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Unit Testing with WOUnit

  • 1. Unit Testing with WOUnit Henrique Prange (HP)
  • 2. • WOUnittest • Wonder’s ERXTestCase • JavaMemoryAdaptor • Ad hoc Testing History
  • 3. Why another framework? • Simple • Fast • Full support for Wonder features • Concise assertions • Test isolation
  • 4. Features • Use the new @Rule • MockEditingContext extends ERXEditingContext • Useful assertions for EOF logic • Compatible with WOUnittest
  • 5. Writing Tests • MockEditingContext annotated with @Rule • Load the required EOModels before running tests • Clear the environment after running each test • Prepare EOs • Play with EOs • Use assertions to verify behavior
  • 6. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @Test public void cantSaveFooWithNullProperty() { Foo foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class); foo.setProperty(null); confirm(foo, cannotBeSavedBecause("Foo must have a property")); } }
  • 7. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @Test public void cantSaveFooWithNullProperty() { Foo foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class); foo.setProperty(null); confirm(foo, cannotBeSavedBecause("Foo must have a property")); } @Test public void canSaveFooWithNotNullProperty() { Foo foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class); foo.setProperty("bar"); confirm(foo, canBeSaved()); } }
  • 8. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); private Foo foo; @Before public void setup() { foo = ERXEOControlUtilities.createAndInsertObject(ec, Foo.class); } @Test public void cantSaveFooWithNullProperty() { foo.setProperty(null); confirm(foo, cannotBeSavedBecause("Foo must have a property")); } @Test public void canSaveFooWithNotNullProperty() { foo.setProperty("bar"); confirm(foo, canBeSaved()); } }
  • 9. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @UnderTest private Foo foo; @Test public void cantSaveFooWithNullProperty() { foo.setProperty(null); confirm(foo, cannotBeSavedBecause("Foo must have a property")); } @Test public void canSaveFooWithNotNullProperty() { foo.setProperty("bar"); confirm(foo, canBeSaved()); } }
  • 10. @UnderTest • Behave as a real object • All validations apply • Alternative to createAndInsertObject
  • 11. Assertions • EOAssert class • EO can/cannot be saved • EO can/cannot be deleted • EO has/hasn’t been saved • EO has/hasn’t been deleted • EC does/doesn’t save changes successfully
  • 13. Dummy Objects • Do not need to be initialized • Because validations don’t apply • @Dummy as alternative to ec.createSavedObject
  • 14. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @UnderTest private Foo foo; @Test public void canSaveFooWithBar() { Bar bar = ec.createSavedObject(Bar.class); foo.setBar(bar); confirm(foo, canBeSaved()); } }
  • 15. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @UnderTest private Foo foo; @Dummy private Bar bar; @Test public void canSaveFooWithBar() { foo.setBar(bar); confirm(foo, canBeSaved()); } }
  • 16. NSArray of EOs • Useful to test toMany relationships • Work with @UnderTest and @Dummy • EOs can be spied with @Spy
  • 17. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @UnderTest private Foo foo; @Dummy private Bar bar1, bar2, bar3, bar4; @Test public void cannotSaveFooWithLessThanFiveBars() { foo.addToBarRelationship(bar1); foo.addToBarRelationship(bar2); foo.addToBarRelationship(bar3); foo.addToBarRelationship(bar4); confirm(foo, cannotBeSaved()); } }
  • 18. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @UnderTest private Foo foo; @Dummy(size = 4) private NSArray<Bar> bars; @Test public void cannotSaveFooWithLessThanFiveBars() { foo.addObjectsToBothSidesOfRelationshipWithKey(bars, Foo.BARS_KEY); confirm(foo, cannotBeSaved()); } }
  • 19. Restrictions • No support for Properties • No support for Localization • No support for SQL operations
  • 21. Spying Objects • Useful to workaround WOUnit limitations • Allows to change and verify behavior • Requires Mockito • @Spy as alternative to spy(new Foo) + insertObject • Requires @RunWith(MockitoJUnitRunner.class)
  • 22. Sample class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @Test public void callSlowMethodWhenDoingSomething() { Foo foo = new Foo(); foo = Mockito.spy(foo); ec.insertObject(foo); Mockito.doNothing().when(foo).slowMethodWithSideEffects(); foo.doSomething(); Mockito.verify(foo).slowMethodWithSideEffects(); } }
  • 23. Sample @RunWith(MockitoJUnitRunner.class) class FooTest { @Rule public MockEditingContext ec = new MockEditingContext("MyModel"); @Spy @UnderTest private Foo foo; @Test public void callSlowMethodWhenDoingSomething() { Mockito.doNothing().when(foo).slowMethodWithSideEffects(); foo.doSomething(); Mockito.verify(foo).slowMethodWithSideEffects(); } }
  • 24. DEMO
  • 25. Future • Improved troubleshooting messaging • Automatically load EOModels • Fix for issue #20
  • 26. License and Distribution • It’s free • Apache 2 license • Source and Binaries • hprange.github.com/wounit • github.com/hprange/wounit • maven.wocommunity.org