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

CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
Alexander Klimetschek
 
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
Ran Mizrahi
 

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

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

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
WO Community
 
Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
WO Community
 
J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드
ksain
 

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 (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

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

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