SlideShare a Scribd company logo
Unit Testing the right way
Expressive, useful, and maintainable testing
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
GOALS OF TESTING
100% Code Coverage
Test coverage is a useful tool for finding untested parts of a codebase.
Test coverage is of little use as a numeric statement of how good your
tests are.
-- Martin Fowler
public static String foo(boolean someCondition){
String bar = null;
if (someCondition) {
bar = "blabla";
}
return bar.trim();
}
100% Code Coverage
assertEquals("blabla", foo(true));
assertEquals("blabla", foo(false));
Line Coverage 100%
Bug Coverage 0%
Reduce Costs
Most of our time is spent on debugging and fixing bugs.
Bugs - if not fixed soon in the development process - cost a lot more than
the development itself
Google est. bug cost when fixed at:
Development time $5
Automated build time $50
Integration testing time $500
System testing time $5000
Tests as documentation
Tests have to be…
1. comprehensive
2. run often and work
3. written to be read
Tests as documentation
Method names are important to keep tests readable
While a very subjective topic, a good practice can be:
dividesAmountByFactor
throws_Illegal_Argument_Exception_When_Dividing_By_Zero
throws_exception_when_dividing_by_zero
private double amount;
public double divide(double factor){
if (factor == 0) throw new IllegalArgumentException();
return amount/factor;
}
Tests as documentation
● Arrange
● Act
● Assert
● Given
● When
● Then
Tests as safety net for refactoring
Tests make you think about your implementation
▪ Tests often trigger refactors and even redesigns
▪ Tests make us really think about the requirements
▪ Tests make us find gaps in the requirements
Conclusion
Write unit tests to…
… reduce costs / save time
… be able to confidently refactor
… look at your technical design from a different angle
… look at your requirements from a different angle
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
WHAT TO TEST
Test isolated units
Keep level of collaboration the smallest possible in units under test
Test isolated units
Smallest possible
Test isolated units
Test in complete
isolation
Test isolated units
No knowledge of implementation details of called method of collaborator
Test isolated units
How ?
Extensive use of mocked-out collaborators in non-leaf objects/classes
Test isolated units
It results mostly in one test-class per class
e.g: MyClass and MyClassTest
Test isolated units
Advantage:
Less tests to write
Smaller tests to write
Less complicated setup of fixtures
Probably all branches covered quickly
Boundary Cases
Test cases that cover the full spectrum of possible values.
Example 1:
A method that accepts only int values between 0 and 100
public void compute(int value){}
Test with -1, 0, 10, 50, 100, 101, 'A'
Boundary Cases
Example 2:
A method that removes a character in a String text
public String remove(String text, char ch)
1. Test for null text
2. Test for empty text
3. Test for character which is not in String
4. Test for characters which comes during start, end or middle of String
5. Test to cover if text String contains just one character which is equal or not equal to the
to be removed one
6. Test with String contains just one character multiple times
Branches
Every time that a different path of execution can be triggered results in a
different branch
Basically: if, else, for, while, do blocks and even collaborators
if(condition){
}
2 branches : if true and if false
Branches: Cyclomatic complexity
Mathematical result of a formula to calculate the complexity of a piece of
code.
Branches: Cyclomatic complexity
Start with a count of one for the method. Add one for
each of the following flow-related elements that are
found in the method.
Methods Each return that isn't the last statement of a method
Selection if, else, case, default
Loops for, while, do-while, break, and continue
Operators &&, ||, ?, and :
Exceptions catch, finally, throw, or throws clause
Threads start() call on a thread. Of course, this is a ridiculous underestimate!
Branches: Cyclomatic complexity
If this number is higher than 10 it becomes nearly impossible to test.
“Impossible to test” = impossible to have full branch coverage
Branches: Cyclomatic complexity
Keep this number low !!
How ?
CLEAN CODE!!!!
Branches: Cyclomatic complexity
Where?
SonarQube calculates this out of the box
Code Coverage
Expresses the amount of production code that is covered by automated
tests
Code Coverage
Code Coverage: Tools
JaCoCo: replacement for Emma, fully supports Java 7 and 8, used by
Sonar, EclEmma(used to be based on EMMA), Jenkins, Netbeans,
IntelliJ IDEA, Gradle
Clover: Atlassian → commercial
Cobertura
Conclusion
What to test :
▪ Completely in isolation
▪ All Boundary cases
▪ All branches
Be aware of :
▪ Cyclomatic complexity
▪ SonarQube calculates it out of the box for you
▪ Branch coverage
▪ Calculation possible by
▪ Jacoco, Emma, Clover, Cobertura
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
FIXTURES
Definition (non-software)
A Fixture in non-software development is e.g.: the setup of a controlled
environment to test the functioning of a piece of hardware
Definition (software)
A fixed state of software under test used as baseline for running tests
= test context
Preparation of input data and setup/creation of fake or mock objects
Definition (software)
Main benefit:
It avoids duplication of code necessary to initialize and clean up common
objects
Use in JUnit
From Junit 4 on there are Java 5 annotations for setting up Test fixture:
@Before, @BeforeClass, @After, @AfterClass
@Before, @BeforeClass, @After, @AfterClass
@BeforeClass
public static void prepareSomeResources()
@Before
public void setUpFixtureForAllTests()
@After
public void freeResourcesAfterEachTest()
@AfterClass
public static void freeResourcesAfterAllTestsRan()
ObjectMother
ObjectMother
Factory for creating fixtures that are used in several test classes.
Catchy name thought of at thoughtworks
http://martinfowler.com/bliki/ObjectMother.html
ObjectMother
private PsychoKiller hanibal;
@Before
public void setupFixtureForHanibalLastKill2DaysAgo(){
hanibal = new PsychoKiller();
hanibal.setFirstName(“Hanibal”);
hanibal.setLastName(“Lecter”);
hanibal.setLastKillDate(current - 2 days);
}
ObjectMother
private PsychoKiller hanibal;
@Before
public void setupFixtureForHanibalLastKill2DaysAgo(){
hanibal = PsychoKillerMother.
getHanibalLastKill2DaysAgo();
}
@Test
public void returns_true_if_less_than_4_days(){
assertTrue(hanibal.killedRecently());
}
Conclusion
▪ Use Fixtures to reduce code duplication
▪ In JUnit 4 : @Before @BeforeClass @After @AfterClass
▪ ObjectMother: to help keeping setup of fixtures small and concise and
in one place so reusable for other test-classes
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
MOCKS
Why?
Mocking, Spies, Stubs, Doubles & fancy buzzwords
Isolate the code under test
Test one object, not the collaborators !
Speed up test execution
Canned replies are fast !
Make execution deterministic
Less variables means more control !
Simulate special condition
Don’t stick to the happy path.
Gain access to hidden information
Can you see The Hidden Tiger?
Our example codebase
Fancy cars !
Codebase: Car
public class Car {
public void setEngine(final Engine engine) {...}
public void start() {...}
public void stop() { … }
}
Codebase: Engine
public interface Engine {
void start();
void stop();
boolean isRunning();
}
public class DieselEngine implements Engine;
GITHUB!
https://github.com/pijalu/mocktype
Play along !
Dummy|Fake|Stubs|Spies|Mocks
Dummy
Dummy objects are passed around but never actually used. Usually they
are just used to fill parameter lists
POJO Dummy
public class TestMockDummy {
final Engine dummyEngine = new DieselEngine();
Car testedCar = new Car(new DieselEngine());
@Test(expected = IllegalStateException.class)
public void testExceptionIfCarStarted() {
testedCar.start();
testedCar.setEngine(dummyEngine);
}
}
Fake
Fake objects have working implementations, but usually take some
shortcut which makes them not suitable for production
POJO Fake
private final Engine fakeEngine = new Engine() {
boolean started=false;
@Override
public void stop() { started=false; }
@Override
public void start() { started=true; }
@Override
public boolean isRunning() { return started; }
};
POJO Fake (cont)
…
private final Car carWithStartableEngine = new Car(fakeEngine);
@Test
public void testCarCanStart() {
carWithStartableEngine.start();
Assert.assertTrue(carWithStartableEngine.isStarted);
}
…
Stubs
Stubs provide canned answers to calls made during the test, usually not
responding at all to anything outside what's programmed for the test.
POJO Stubs
private final Engine stubEngine = new Engine() {
@Override
public void stop() {}
@Override
public void start() {}
@Override
public boolean isRunning() { return false; }
};
POJO Subs (cont)
private final Car car = new Car(stubEngine);
@Test
public void testCarDoesNotStartWithoutEngine() {
car.start();
Assert.assertFalse(car.isStarted);
}
Spies
NSA your calls.
POJO Spies
private class SpyEngine extends DieselEngine {
int startedCalledCount = 0;
@Override
public void start() {
startedCalledCount++;
super.start();
}
};
POJO Spies (cont)
private final SpyEngine spyEngine = new SpyEngine();
private final Car spiedTestCar = new Car(spyEngine);
@Test
public void testCarStartStartsTheEngine() {
spiedTestCar.start();
Assert.assertEquals("Engine start is called once",
1, spyEngine.startedCalledCount);
}
Mocks
Objects pre-programmed with expectations which form a specification of
the calls they are expected to receive.
EasyMock: Mock (too lazy)
@RunWith(EasyMockRunner.class)
public class TestMockEasyMock
extends EasyMockSupport{
@Mock
Engine mockEngine;
…
EasyMock: Mock (cont)
@Test
public void testCarWithAMockedEngine() {
// Set the behavior
expect(mockEngine.isRunning()).andReturn(false);
mockEngine.start();
expect(mockEngine.isRunning()).andReturn(true);
mockEngine.stop();
replayAll();
EasyMock: Mock (cont 2)
// Set a car with our mocked engine
Car testedCar = new Car(mockEngine);
// Run !
testedCar.start();
testedCar.stop();
// Verify !
verifyAll();
}
POJO feels a bit ghetto ?
(Some) Existing frameworks
▪ EasyMock
▪ Mockito
▪ Unitils
▪ JMockit
And Much Much more !
Proxy Based
Class remap
Strict by default
Non-Strict by
default
EasyMock
1. Arrange: Create the mock and setup behavior
mock = createMock(Collaborator.class);
mock.documentChanged("Document");
expectLastCall().times(3);
expect(mock.vote("Document")).andReturn((byte)-42);
replay(mock);
3. ACT !
classUnderTest.addDocument("Document", "content");
4. Assert
verify(mock);
Mockito - Behavior Check
1. Arrange
List mockedList = mock(List.class);
2. Act
mockedList.add("one");
mockedList.clear();
3. Assert
verify(mockedList).add("one");
verify(mockedList).clear();
Mockito - Stubbing
1. Arrange
LinkedList mockedList = mock(LinkedList.class);
when(mockedList.get(0)).thenReturn("first");
when(mockedList.get(1))
.thenThrow(new RuntimeException());
2. Act (examples)
System.out.println(mockedList.get(0));
System.out.println(mockedList.get(1));
System.out.println(mockedList.get(999));
Unitils (mocking)
1. Arrange (Create the mock and setup behavior)
myServiceMock =
new MockObject<MyService>(MyService.class, this);
myServiceMock.returns("a value").someMethod();
2. Act
myServiceMock.getMock().someMethod();
3. Assert !
myServiceMock.assertNotInvoked().someMethod();
JMockit - Expectations
@Test
public void aTestMethod(@Mocked final MyCollaborator mock){
new NonStrictExpectations() {{
mock.getData(); result = "my test data";
mock.doSomething(anyInt, "some expected value", anyString);
times=1;
}};
// In the replay phase, the tested method would call the "getData" and "doSomething"
// methods on a "MyCollaborator" instance.
...
// In the verify phase, we may optionally verify expected invocations to
// "MyCollaborator" objects.
...
}
JMockit - Verification
...
new Verifications() {{
// If no new instance of the mocked class should have been
// created with the no-args constructor, we can verify it:
new MyCollaborator(); times = 0;
// Here we verify that doSomething() was executed at least once:
mock.doSomething();
// Another verification, which must have occurred no more than three
// times:
mock.someOtherMethod(
anyBoolean, any, withInstanceOf(Xyz.class)); maxTimes = 3;
}};
}
Conclusion
▪ Mocking helps you to create better tests
▪ Mocking Framework(s) help keeping overhead low
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
ASSERTIONS
Assertions
What ?
Verify if the result of the test is what we expected.
Assertions
How ?
Should be automated, no human intervention necessary
No logging, System.out.println() etc. to be used
Use framework(s) to achieve this.
Junit assertions
Types
assertEquals, assertSame, assertTrue,
assertFalse, assertNull, assertNotNull
Advantages
Most often used, so best known.
Junit assertions
Drawbacks
▪ Not always very readable
assertEquals(expected, result) or assertEquals(result, expected)
▪ Number of assertions are limited
▪ Comparing (complex) objects is hard.
impossible when object has not equals() implemented !
Conclusion
It’s ok to use them for primitive types.
But there are better alternatives.
Hamcrest assertions
What ?
▪ Hamcrest is a framework for writing matcher objects allowing ‘match’
rules to be defined declaratively.
assertThat(Object, Matcher<T>);
▪ Can easily be integrated with other frameworks like Junit, TestNG,
Mockito, EasyMock, Jmock,...
Hamcrest assertions
Advantages
▪ Improved readability of tests
assertThat(ObjectToBeChecked, equalTo(OtherObject))
assertThat(ObjectToBeChecked, is(equalTo(OtherObject));
assertThat(collection, hasSize(2);
▪ Better failure message
assertThat(3, greaterThan(5));
Expected: a value greater than <5>
but: <3> was less than <5>
Hamcrest assertions
▪ Combination of Matchers
Allows to assert more precisely.
assertThat(array, not(emptyArray());
assertThat(collections, everyItem(greaterThan(10));
▪ Write your own Matcher
This can occur when you find a fragment of code that test the same set of properties over and over
again and you want to bundle the fragment into a single assertion.
But be aware, there are already plenty of matchers available, make sure you are not writing existing
code again.
Hamcrest assertions
Example :
To test if a double has a value NaN (not a number)
Test we want to write :
public void testSquareRootOfMinusOneIsNotANumber () {
assertThat(Math.sqrt(-1), is(notANumber()));
}
public class IsNotANumber extends TypeSafeMatcher<Double> {
@Override
public boolean matchesSafely(Double number) {
return number.isNaN();
}
public void describeTo(Description description) {
description.appendText("not a number");
}
@Factory
public static <T> Matcher<Double> notANumber() {
return new IsNotANumber();
}
}
Hamcrest assertions
Hamcrest assertions
▪ More possibilities to compare objects
It is possible to check objects that don’t have equals() implemented.
assertThat(ObjectToBeChecked, samePropertyValuesAs(OtherObject));
but not possible for objects with composition !
Better use ReflectionAssert.assertReflectionEquals of unitils !
Hamcrest assertions
Drawbacks
▪ Finding the right Matcher
The matchers are not set in one place. Most matchers are accessible via the Matcher class,
but some are located in the CoreMatcher class, and some are in another package.
example:
hasItem() : Matcher class
hasItems() : IsCollectionContaining class
Other frameworks
Unitils
▪ ReflectionAssert
This assertion loops over all fields in both objects and compares their values using reflection. If a
field value itself is also an object, it will recursively be compared field by field using reflection. The
same is true for collections, maps and arrays.
▪ Lenient assertions
Adding some levels of leniency to the ReflectionAssert checks. (order list, ignoring defaults, dates,
assertLenientEquals)
▪ Property assertions
Methods to compare a specific property of two objects
assertPropertyLenientEquals("id", 1, user);
assertPropertyLenientEquals("address.street", "First street", user);
Other frameworks
Fest (http://code.google.com/p/fest/)
Supports both Junit and TestNG
assertThat(collection).hasSize(6).contains(frodo, sam);
Assertions
Misuse of assertions
▪ Manual assertions
This practice misses out the main benefits of testing automation —
the ability to continuously run the tests in the background without intervention
■ Multiple assertions
■ Redundant assertions
Extra calls to an assert method where the condition being tested is a hard coded value
assertTrue(“always true”, true)
■ Using the wrong assertions
assertTrue("Object must be null", actual == null);
assertTrue("Object must not be null", actual != null);
Assertions
What about void methods ?
Often if a method doesn't return a value, it will have some side effect. There may be a way to verify
that the side effect actually occurred as expected.
Especially exception testing should not be forgotten.
Assertions
MyClass {
public void addElement(String element, List<String> elements) {
elements.add(element);
}
}
public void testAddElement() {
List<String> elements = new ArrayList();
assertEquals(0, elements.size() );
myClassTest.addElement(“test”, elements);
assertEquals(1, elements.size() );
}
Conclusion
▪ Always make sure your assertions are fully automated
▪ Junit assertions are ok for primitive types
▪ Hamcrest offers a lot of interesting matchers that allows you to assert
more precise
▪ Unitils is a better alternative when comparing objects
▪ You can use them all together !
The Red Line
Goal of Testing
What to Test
Fixtures
Mocks
Assertions
Question ?
PRACTICAL
Exercises !
github: https://github.com/pijalu/utdemo
▪ Master: Default start
▪ Branches: Different solutions with different mocking framework…
Don’t look ;-)
Factoid - Model
Fact
▪ Simple POJO
▪ Stores a fact
▪ It’s a string
Factoid - Provider
Provider interface:
▪ Provides a list of fact to a client
▪ int size(): Number of facts in the provider
▪ Fact getFact(index): Return a fact (0->size-1)
▪ Implementation:
▪ FileFactProvider
▪ Loads facts from a file.
▪ Line oriented
Factoid- Service
FactService interface:
▪ Returns a fact to client:
▪ Fact getAFact(): Return a fact
▪ Implementation:
▪ RandomFactService:
▪ Returns a random fact using a provider
▪ Uses Random
▪ Builds an array to avoid repetition/ensure all facts are returned
Factoid - Main
Factoid main class
▪ Loads a File with a (File)FactProvider
▪ Loads a (Random)FactService using created fact provider
▪ Calls FactService getAFact()
Factoid - What to do
▪ Select the mocking framework you want
▪ EasyMock to start !
▪ Check the FIXME in the existing code
▪ Fix as many as you can !
▪ Be creative
▪ Look for other issues ;-)
GO !
Thanks for your attendance
Ad

More Related Content

What's hot (20)

Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
Stephen Fuqua
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
Engineor
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
Dave Haeffner
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and Selenium
Nikolay Vasilev
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
Fwdays
 
JavaScript Metaprogramming with ES 2015 Proxy
JavaScript Metaprogramming with ES 2015 ProxyJavaScript Metaprogramming with ES 2015 Proxy
JavaScript Metaprogramming with ES 2015 Proxy
Alexandr Skachkov
 
PL/SQL unit testing with Ruby
PL/SQL unit testing with RubyPL/SQL unit testing with Ruby
PL/SQL unit testing with Ruby
Raimonds Simanovskis
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
 
201502 - Integration Testing
201502 - Integration Testing201502 - Integration Testing
201502 - Integration Testing
lyonjug
 
Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018
Ortus Solutions, Corp
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
christophd
 
Jbehave selenium
Jbehave seleniumJbehave selenium
Jbehave selenium
Vadim Goncharenko
 
Jbehave- Basics to Advance
Jbehave- Basics to AdvanceJbehave- Basics to Advance
Jbehave- Basics to Advance
Ravinder Singh
 
Visual studio performance testing quick reference guide 3 6
Visual studio performance testing quick reference guide 3 6Visual studio performance testing quick reference guide 3 6
Visual studio performance testing quick reference guide 3 6
Srimanta Kumar Sahu
 
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracleprohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Jacek Gebal
 
Automation Frame works Instruction Sheet
Automation Frame works Instruction SheetAutomation Frame works Instruction Sheet
Automation Frame works Instruction Sheet
vodQA
 
Create an architecture for web test automation
Create an architecture for web test automationCreate an architecture for web test automation
Create an architecture for web test automation
Elias Nogueira
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
Rachid Kherrazi
 
Test
TestTest
Test
Eddie Kao
 
Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
Stephen Fuqua
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
Engineor
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
Dave Haeffner
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and Selenium
Nikolay Vasilev
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
Fwdays
 
JavaScript Metaprogramming with ES 2015 Proxy
JavaScript Metaprogramming with ES 2015 ProxyJavaScript Metaprogramming with ES 2015 Proxy
JavaScript Metaprogramming with ES 2015 Proxy
Alexandr Skachkov
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
 
201502 - Integration Testing
201502 - Integration Testing201502 - Integration Testing
201502 - Integration Testing
lyonjug
 
Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018
Ortus Solutions, Corp
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
christophd
 
Jbehave- Basics to Advance
Jbehave- Basics to AdvanceJbehave- Basics to Advance
Jbehave- Basics to Advance
Ravinder Singh
 
Visual studio performance testing quick reference guide 3 6
Visual studio performance testing quick reference guide 3 6Visual studio performance testing quick reference guide 3 6
Visual studio performance testing quick reference guide 3 6
Srimanta Kumar Sahu
 
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracleprohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Jacek Gebal
 
Automation Frame works Instruction Sheet
Automation Frame works Instruction SheetAutomation Frame works Instruction Sheet
Automation Frame works Instruction Sheet
vodQA
 
Create an architecture for web test automation
Create an architecture for web test automationCreate an architecture for web test automation
Create an architecture for web test automation
Elias Nogueira
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
Rachid Kherrazi
 

Viewers also liked (20)

AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
Prince Norin
 
Unit testing
Unit testingUnit testing
Unit testing
Adam Birr
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
Rotem Tamir
 
mwpc gas gain report
mwpc gas gain reportmwpc gas gain report
mwpc gas gain report
Andrew Schick
 
Mongodb @ vrt
Mongodb @ vrtMongodb @ vrt
Mongodb @ vrt
JWORKS powered by Ordina
 
Batch Processing - A&BP CC
Batch Processing - A&BP CCBatch Processing - A&BP CC
Batch Processing - A&BP CC
JWORKS powered by Ordina
 
Responsive web - CC FE & UX
Responsive web -  CC FE & UXResponsive web -  CC FE & UX
Responsive web - CC FE & UX
JWORKS powered by Ordina
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014
JWORKS powered by Ordina
 
Meteor - JOIN 2015
Meteor - JOIN 2015Meteor - JOIN 2015
Meteor - JOIN 2015
JWORKS powered by Ordina
 
Clean Code - A&BP CC
Clean Code - A&BP CCClean Code - A&BP CC
Clean Code - A&BP CC
JWORKS powered by Ordina
 
Big data document and graph d bs - couch-db and orientdb
Big data  document and graph d bs - couch-db and orientdbBig data  document and graph d bs - couch-db and orientdb
Big data document and graph d bs - couch-db and orientdb
JWORKS powered by Ordina
 
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
Microservices with Netflix OSS & Hypermedia APIs - JavaDay KievMicroservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
JWORKS powered by Ordina
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
JWORKS powered by Ordina
 
Spring REST Docs: Documenting RESTful APIs using your tests - Devoxx
Spring REST Docs: Documenting RESTful APIs using your tests - DevoxxSpring REST Docs: Documenting RESTful APIs using your tests - Devoxx
Spring REST Docs: Documenting RESTful APIs using your tests - Devoxx
JWORKS powered by Ordina
 
Shirly Ronen - User story testing activities
Shirly Ronen - User story testing activitiesShirly Ronen - User story testing activities
Shirly Ronen - User story testing activities
AgileSparks
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
JWORKS powered by Ordina
 
Hadoop bootcamp getting started
Hadoop bootcamp getting startedHadoop bootcamp getting started
Hadoop bootcamp getting started
JWORKS powered by Ordina
 
An introduction to Cloud Foundry
An introduction to Cloud FoundryAn introduction to Cloud Foundry
An introduction to Cloud Foundry
JWORKS powered by Ordina
 
SAP SuccessFactors With BGBS MENA
SAP SuccessFactors With BGBS MENASAP SuccessFactors With BGBS MENA
SAP SuccessFactors With BGBS MENA
Darem Alkhayer
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
Prince Norin
 
Unit testing
Unit testingUnit testing
Unit testing
Adam Birr
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
Rotem Tamir
 
mwpc gas gain report
mwpc gas gain reportmwpc gas gain report
mwpc gas gain report
Andrew Schick
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014
JWORKS powered by Ordina
 
Big data document and graph d bs - couch-db and orientdb
Big data  document and graph d bs - couch-db and orientdbBig data  document and graph d bs - couch-db and orientdb
Big data document and graph d bs - couch-db and orientdb
JWORKS powered by Ordina
 
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
Microservices with Netflix OSS & Hypermedia APIs - JavaDay KievMicroservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
JWORKS powered by Ordina
 
Spring REST Docs: Documenting RESTful APIs using your tests - Devoxx
Spring REST Docs: Documenting RESTful APIs using your tests - DevoxxSpring REST Docs: Documenting RESTful APIs using your tests - Devoxx
Spring REST Docs: Documenting RESTful APIs using your tests - Devoxx
JWORKS powered by Ordina
 
Shirly Ronen - User story testing activities
Shirly Ronen - User story testing activitiesShirly Ronen - User story testing activities
Shirly Ronen - User story testing activities
AgileSparks
 
SAP SuccessFactors With BGBS MENA
SAP SuccessFactors With BGBS MENASAP SuccessFactors With BGBS MENA
SAP SuccessFactors With BGBS MENA
Darem Alkhayer
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
Ad

Similar to Unit testing - A&BP CC (20)

Mocking with Mockito
Mocking with MockitoMocking with Mockito
Mocking with Mockito
Paul Churchward
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
guillaumecarre
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
Dror Helper
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
Ying Zhang
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
guest268ee8
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
Giovanni Scerra ☃
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Anand Kumar Rajana
 
J Unit
J UnitJ Unit
J Unit
guest333f37c3
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
Attila Bertók
 
Google mock training
Google mock trainingGoogle mock training
Google mock training
Thierry Gayet
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
Dror Helper
 
Software Engineering - RS3
Software Engineering - RS3Software Engineering - RS3
Software Engineering - RS3
AtakanAral
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
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
Tricode (part of Dept)
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
Mark Wragg
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
guillaumecarre
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
Dror Helper
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
Ying Zhang
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
guest268ee8
 
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
 
Google mock training
Google mock trainingGoogle mock training
Google mock training
Thierry Gayet
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
Dror Helper
 
Software Engineering - RS3
Software Engineering - RS3Software Engineering - RS3
Software Engineering - RS3
AtakanAral
 
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
Tricode (part of Dept)
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
Mark Wragg
 
Ad

More from JWORKS powered by Ordina (17)

Introduction to Webpack - Ordina JWorks - CC JS & Web
Introduction to Webpack - Ordina JWorks - CC JS & WebIntroduction to Webpack - Ordina JWorks - CC JS & Web
Introduction to Webpack - Ordina JWorks - CC JS & Web
JWORKS powered by Ordina
 
Lagom in Practice
Lagom in PracticeLagom in Practice
Lagom in Practice
JWORKS powered by Ordina
 
Netflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLandNetflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 
Cc internet of things @ Thomas More
Cc internet of things @ Thomas MoreCc internet of things @ Thomas More
Cc internet of things @ Thomas More
JWORKS powered by Ordina
 
Cc internet of things LoRa and IoT - Innovation Enablers
Cc internet of things   LoRa and IoT - Innovation Enablers Cc internet of things   LoRa and IoT - Innovation Enablers
Cc internet of things LoRa and IoT - Innovation Enablers
JWORKS powered by Ordina
 
Big data key-value and column stores redis - cassandra
Big data  key-value and column stores redis - cassandraBig data  key-value and column stores redis - cassandra
Big data key-value and column stores redis - cassandra
JWORKS powered by Ordina
 
Big data elasticsearch practical
Big data  elasticsearch practicalBig data  elasticsearch practical
Big data elasticsearch practical
JWORKS powered by Ordina
 
Intro to cassandra
Intro to cassandraIntro to cassandra
Intro to cassandra
JWORKS powered by Ordina
 
Android wear - CC Mobile
Android wear - CC MobileAndroid wear - CC Mobile
Android wear - CC Mobile
JWORKS powered by Ordina
 
Spring 4 - A&BP CC
Spring 4 - A&BP CCSpring 4 - A&BP CC
Spring 4 - A&BP CC
JWORKS powered by Ordina
 
Android secure offline storage - CC Mobile
Android secure offline storage - CC MobileAndroid secure offline storage - CC Mobile
Android secure offline storage - CC Mobile
JWORKS powered by Ordina
 
Java 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CCJava 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CC
JWORKS powered by Ordina
 
IoT: A glance into the future
IoT: A glance into the futureIoT: A glance into the future
IoT: A glance into the future
JWORKS powered by Ordina
 
Workshop Ionic Framework - CC FE & UX
Workshop Ionic Framework - CC FE & UXWorkshop Ionic Framework - CC FE & UX
Workshop Ionic Framework - CC FE & UX
JWORKS powered by Ordina
 
IoT: LoRa and Java on the PI
IoT: LoRa and Java on the PIIoT: LoRa and Java on the PI
IoT: LoRa and Java on the PI
JWORKS powered by Ordina
 
IoT: An introduction
IoT: An introductionIoT: An introduction
IoT: An introduction
JWORKS powered by Ordina
 
Unit Testing in AngularJS - CC FE & UX
Unit Testing in AngularJS -  CC FE & UXUnit Testing in AngularJS -  CC FE & UX
Unit Testing in AngularJS - CC FE & UX
JWORKS powered by Ordina
 
Introduction to Webpack - Ordina JWorks - CC JS & Web
Introduction to Webpack - Ordina JWorks - CC JS & WebIntroduction to Webpack - Ordina JWorks - CC JS & Web
Introduction to Webpack - Ordina JWorks - CC JS & Web
JWORKS powered by Ordina
 
Netflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLandNetflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 
Cc internet of things LoRa and IoT - Innovation Enablers
Cc internet of things   LoRa and IoT - Innovation Enablers Cc internet of things   LoRa and IoT - Innovation Enablers
Cc internet of things LoRa and IoT - Innovation Enablers
JWORKS powered by Ordina
 
Big data key-value and column stores redis - cassandra
Big data  key-value and column stores redis - cassandraBig data  key-value and column stores redis - cassandra
Big data key-value and column stores redis - cassandra
JWORKS powered by Ordina
 
Android secure offline storage - CC Mobile
Android secure offline storage - CC MobileAndroid secure offline storage - CC Mobile
Android secure offline storage - CC Mobile
JWORKS powered by Ordina
 

Recently uploaded (20)

LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 

Unit testing - A&BP CC

  • 1. Unit Testing the right way Expressive, useful, and maintainable testing
  • 2. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 3. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 5. 100% Code Coverage Test coverage is a useful tool for finding untested parts of a codebase. Test coverage is of little use as a numeric statement of how good your tests are. -- Martin Fowler
  • 6. public static String foo(boolean someCondition){ String bar = null; if (someCondition) { bar = "blabla"; } return bar.trim(); } 100% Code Coverage assertEquals("blabla", foo(true)); assertEquals("blabla", foo(false)); Line Coverage 100% Bug Coverage 0%
  • 7. Reduce Costs Most of our time is spent on debugging and fixing bugs. Bugs - if not fixed soon in the development process - cost a lot more than the development itself Google est. bug cost when fixed at: Development time $5 Automated build time $50 Integration testing time $500 System testing time $5000
  • 8. Tests as documentation Tests have to be… 1. comprehensive 2. run often and work 3. written to be read
  • 9. Tests as documentation Method names are important to keep tests readable While a very subjective topic, a good practice can be: dividesAmountByFactor throws_Illegal_Argument_Exception_When_Dividing_By_Zero throws_exception_when_dividing_by_zero private double amount; public double divide(double factor){ if (factor == 0) throw new IllegalArgumentException(); return amount/factor; }
  • 10. Tests as documentation ● Arrange ● Act ● Assert ● Given ● When ● Then
  • 11. Tests as safety net for refactoring
  • 12. Tests make you think about your implementation ▪ Tests often trigger refactors and even redesigns ▪ Tests make us really think about the requirements ▪ Tests make us find gaps in the requirements
  • 13. Conclusion Write unit tests to… … reduce costs / save time … be able to confidently refactor … look at your technical design from a different angle … look at your requirements from a different angle
  • 14. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 16. Test isolated units Keep level of collaboration the smallest possible in units under test
  • 18. Test isolated units Test in complete isolation
  • 19. Test isolated units No knowledge of implementation details of called method of collaborator
  • 20. Test isolated units How ? Extensive use of mocked-out collaborators in non-leaf objects/classes
  • 21. Test isolated units It results mostly in one test-class per class e.g: MyClass and MyClassTest
  • 22. Test isolated units Advantage: Less tests to write Smaller tests to write Less complicated setup of fixtures Probably all branches covered quickly
  • 23. Boundary Cases Test cases that cover the full spectrum of possible values. Example 1: A method that accepts only int values between 0 and 100 public void compute(int value){} Test with -1, 0, 10, 50, 100, 101, 'A'
  • 24. Boundary Cases Example 2: A method that removes a character in a String text public String remove(String text, char ch) 1. Test for null text 2. Test for empty text 3. Test for character which is not in String 4. Test for characters which comes during start, end or middle of String 5. Test to cover if text String contains just one character which is equal or not equal to the to be removed one 6. Test with String contains just one character multiple times
  • 25. Branches Every time that a different path of execution can be triggered results in a different branch Basically: if, else, for, while, do blocks and even collaborators if(condition){ } 2 branches : if true and if false
  • 26. Branches: Cyclomatic complexity Mathematical result of a formula to calculate the complexity of a piece of code.
  • 27. Branches: Cyclomatic complexity Start with a count of one for the method. Add one for each of the following flow-related elements that are found in the method. Methods Each return that isn't the last statement of a method Selection if, else, case, default Loops for, while, do-while, break, and continue Operators &&, ||, ?, and : Exceptions catch, finally, throw, or throws clause Threads start() call on a thread. Of course, this is a ridiculous underestimate!
  • 28. Branches: Cyclomatic complexity If this number is higher than 10 it becomes nearly impossible to test. “Impossible to test” = impossible to have full branch coverage
  • 29. Branches: Cyclomatic complexity Keep this number low !! How ? CLEAN CODE!!!!
  • 30. Branches: Cyclomatic complexity Where? SonarQube calculates this out of the box
  • 31. Code Coverage Expresses the amount of production code that is covered by automated tests
  • 33. Code Coverage: Tools JaCoCo: replacement for Emma, fully supports Java 7 and 8, used by Sonar, EclEmma(used to be based on EMMA), Jenkins, Netbeans, IntelliJ IDEA, Gradle Clover: Atlassian → commercial Cobertura
  • 34. Conclusion What to test : ▪ Completely in isolation ▪ All Boundary cases ▪ All branches Be aware of : ▪ Cyclomatic complexity ▪ SonarQube calculates it out of the box for you ▪ Branch coverage ▪ Calculation possible by ▪ Jacoco, Emma, Clover, Cobertura
  • 35. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 37. Definition (non-software) A Fixture in non-software development is e.g.: the setup of a controlled environment to test the functioning of a piece of hardware
  • 38. Definition (software) A fixed state of software under test used as baseline for running tests = test context Preparation of input data and setup/creation of fake or mock objects
  • 39. Definition (software) Main benefit: It avoids duplication of code necessary to initialize and clean up common objects
  • 40. Use in JUnit From Junit 4 on there are Java 5 annotations for setting up Test fixture: @Before, @BeforeClass, @After, @AfterClass
  • 41. @Before, @BeforeClass, @After, @AfterClass @BeforeClass public static void prepareSomeResources() @Before public void setUpFixtureForAllTests() @After public void freeResourcesAfterEachTest() @AfterClass public static void freeResourcesAfterAllTestsRan()
  • 43. ObjectMother Factory for creating fixtures that are used in several test classes. Catchy name thought of at thoughtworks http://martinfowler.com/bliki/ObjectMother.html
  • 44. ObjectMother private PsychoKiller hanibal; @Before public void setupFixtureForHanibalLastKill2DaysAgo(){ hanibal = new PsychoKiller(); hanibal.setFirstName(“Hanibal”); hanibal.setLastName(“Lecter”); hanibal.setLastKillDate(current - 2 days); }
  • 45. ObjectMother private PsychoKiller hanibal; @Before public void setupFixtureForHanibalLastKill2DaysAgo(){ hanibal = PsychoKillerMother. getHanibalLastKill2DaysAgo(); } @Test public void returns_true_if_less_than_4_days(){ assertTrue(hanibal.killedRecently()); }
  • 46. Conclusion ▪ Use Fixtures to reduce code duplication ▪ In JUnit 4 : @Before @BeforeClass @After @AfterClass ▪ ObjectMother: to help keeping setup of fixtures small and concise and in one place so reusable for other test-classes
  • 47. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 48. MOCKS
  • 49. Why? Mocking, Spies, Stubs, Doubles & fancy buzzwords
  • 50. Isolate the code under test Test one object, not the collaborators !
  • 51. Speed up test execution Canned replies are fast !
  • 52. Make execution deterministic Less variables means more control !
  • 53. Simulate special condition Don’t stick to the happy path.
  • 54. Gain access to hidden information Can you see The Hidden Tiger?
  • 56. Codebase: Car public class Car { public void setEngine(final Engine engine) {...} public void start() {...} public void stop() { … } }
  • 57. Codebase: Engine public interface Engine { void start(); void stop(); boolean isRunning(); } public class DieselEngine implements Engine;
  • 60. Dummy Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists
  • 61. POJO Dummy public class TestMockDummy { final Engine dummyEngine = new DieselEngine(); Car testedCar = new Car(new DieselEngine()); @Test(expected = IllegalStateException.class) public void testExceptionIfCarStarted() { testedCar.start(); testedCar.setEngine(dummyEngine); } }
  • 62. Fake Fake objects have working implementations, but usually take some shortcut which makes them not suitable for production
  • 63. POJO Fake private final Engine fakeEngine = new Engine() { boolean started=false; @Override public void stop() { started=false; } @Override public void start() { started=true; } @Override public boolean isRunning() { return started; } };
  • 64. POJO Fake (cont) … private final Car carWithStartableEngine = new Car(fakeEngine); @Test public void testCarCanStart() { carWithStartableEngine.start(); Assert.assertTrue(carWithStartableEngine.isStarted); } …
  • 65. Stubs Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed for the test.
  • 66. POJO Stubs private final Engine stubEngine = new Engine() { @Override public void stop() {} @Override public void start() {} @Override public boolean isRunning() { return false; } };
  • 67. POJO Subs (cont) private final Car car = new Car(stubEngine); @Test public void testCarDoesNotStartWithoutEngine() { car.start(); Assert.assertFalse(car.isStarted); }
  • 69. POJO Spies private class SpyEngine extends DieselEngine { int startedCalledCount = 0; @Override public void start() { startedCalledCount++; super.start(); } };
  • 70. POJO Spies (cont) private final SpyEngine spyEngine = new SpyEngine(); private final Car spiedTestCar = new Car(spyEngine); @Test public void testCarStartStartsTheEngine() { spiedTestCar.start(); Assert.assertEquals("Engine start is called once", 1, spyEngine.startedCalledCount); }
  • 71. Mocks Objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
  • 72. EasyMock: Mock (too lazy) @RunWith(EasyMockRunner.class) public class TestMockEasyMock extends EasyMockSupport{ @Mock Engine mockEngine; …
  • 73. EasyMock: Mock (cont) @Test public void testCarWithAMockedEngine() { // Set the behavior expect(mockEngine.isRunning()).andReturn(false); mockEngine.start(); expect(mockEngine.isRunning()).andReturn(true); mockEngine.stop(); replayAll();
  • 74. EasyMock: Mock (cont 2) // Set a car with our mocked engine Car testedCar = new Car(mockEngine); // Run ! testedCar.start(); testedCar.stop(); // Verify ! verifyAll(); }
  • 75. POJO feels a bit ghetto ?
  • 76. (Some) Existing frameworks ▪ EasyMock ▪ Mockito ▪ Unitils ▪ JMockit And Much Much more ! Proxy Based Class remap Strict by default Non-Strict by default
  • 77. EasyMock 1. Arrange: Create the mock and setup behavior mock = createMock(Collaborator.class); mock.documentChanged("Document"); expectLastCall().times(3); expect(mock.vote("Document")).andReturn((byte)-42); replay(mock); 3. ACT ! classUnderTest.addDocument("Document", "content"); 4. Assert verify(mock);
  • 78. Mockito - Behavior Check 1. Arrange List mockedList = mock(List.class); 2. Act mockedList.add("one"); mockedList.clear(); 3. Assert verify(mockedList).add("one"); verify(mockedList).clear();
  • 79. Mockito - Stubbing 1. Arrange LinkedList mockedList = mock(LinkedList.class); when(mockedList.get(0)).thenReturn("first"); when(mockedList.get(1)) .thenThrow(new RuntimeException()); 2. Act (examples) System.out.println(mockedList.get(0)); System.out.println(mockedList.get(1)); System.out.println(mockedList.get(999));
  • 80. Unitils (mocking) 1. Arrange (Create the mock and setup behavior) myServiceMock = new MockObject<MyService>(MyService.class, this); myServiceMock.returns("a value").someMethod(); 2. Act myServiceMock.getMock().someMethod(); 3. Assert ! myServiceMock.assertNotInvoked().someMethod();
  • 81. JMockit - Expectations @Test public void aTestMethod(@Mocked final MyCollaborator mock){ new NonStrictExpectations() {{ mock.getData(); result = "my test data"; mock.doSomething(anyInt, "some expected value", anyString); times=1; }}; // In the replay phase, the tested method would call the "getData" and "doSomething" // methods on a "MyCollaborator" instance. ... // In the verify phase, we may optionally verify expected invocations to // "MyCollaborator" objects. ... }
  • 82. JMockit - Verification ... new Verifications() {{ // If no new instance of the mocked class should have been // created with the no-args constructor, we can verify it: new MyCollaborator(); times = 0; // Here we verify that doSomething() was executed at least once: mock.doSomething(); // Another verification, which must have occurred no more than three // times: mock.someOtherMethod( anyBoolean, any, withInstanceOf(Xyz.class)); maxTimes = 3; }}; }
  • 83. Conclusion ▪ Mocking helps you to create better tests ▪ Mocking Framework(s) help keeping overhead low
  • 84. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 86. Assertions What ? Verify if the result of the test is what we expected.
  • 87. Assertions How ? Should be automated, no human intervention necessary No logging, System.out.println() etc. to be used Use framework(s) to achieve this.
  • 88. Junit assertions Types assertEquals, assertSame, assertTrue, assertFalse, assertNull, assertNotNull Advantages Most often used, so best known.
  • 89. Junit assertions Drawbacks ▪ Not always very readable assertEquals(expected, result) or assertEquals(result, expected) ▪ Number of assertions are limited ▪ Comparing (complex) objects is hard. impossible when object has not equals() implemented ! Conclusion It’s ok to use them for primitive types. But there are better alternatives.
  • 90. Hamcrest assertions What ? ▪ Hamcrest is a framework for writing matcher objects allowing ‘match’ rules to be defined declaratively. assertThat(Object, Matcher<T>); ▪ Can easily be integrated with other frameworks like Junit, TestNG, Mockito, EasyMock, Jmock,...
  • 91. Hamcrest assertions Advantages ▪ Improved readability of tests assertThat(ObjectToBeChecked, equalTo(OtherObject)) assertThat(ObjectToBeChecked, is(equalTo(OtherObject)); assertThat(collection, hasSize(2); ▪ Better failure message assertThat(3, greaterThan(5)); Expected: a value greater than <5> but: <3> was less than <5>
  • 92. Hamcrest assertions ▪ Combination of Matchers Allows to assert more precisely. assertThat(array, not(emptyArray()); assertThat(collections, everyItem(greaterThan(10)); ▪ Write your own Matcher This can occur when you find a fragment of code that test the same set of properties over and over again and you want to bundle the fragment into a single assertion. But be aware, there are already plenty of matchers available, make sure you are not writing existing code again.
  • 93. Hamcrest assertions Example : To test if a double has a value NaN (not a number) Test we want to write : public void testSquareRootOfMinusOneIsNotANumber () { assertThat(Math.sqrt(-1), is(notANumber())); }
  • 94. public class IsNotANumber extends TypeSafeMatcher<Double> { @Override public boolean matchesSafely(Double number) { return number.isNaN(); } public void describeTo(Description description) { description.appendText("not a number"); } @Factory public static <T> Matcher<Double> notANumber() { return new IsNotANumber(); } } Hamcrest assertions
  • 95. Hamcrest assertions ▪ More possibilities to compare objects It is possible to check objects that don’t have equals() implemented. assertThat(ObjectToBeChecked, samePropertyValuesAs(OtherObject)); but not possible for objects with composition ! Better use ReflectionAssert.assertReflectionEquals of unitils !
  • 96. Hamcrest assertions Drawbacks ▪ Finding the right Matcher The matchers are not set in one place. Most matchers are accessible via the Matcher class, but some are located in the CoreMatcher class, and some are in another package. example: hasItem() : Matcher class hasItems() : IsCollectionContaining class
  • 97. Other frameworks Unitils ▪ ReflectionAssert This assertion loops over all fields in both objects and compares their values using reflection. If a field value itself is also an object, it will recursively be compared field by field using reflection. The same is true for collections, maps and arrays. ▪ Lenient assertions Adding some levels of leniency to the ReflectionAssert checks. (order list, ignoring defaults, dates, assertLenientEquals) ▪ Property assertions Methods to compare a specific property of two objects assertPropertyLenientEquals("id", 1, user); assertPropertyLenientEquals("address.street", "First street", user);
  • 98. Other frameworks Fest (http://code.google.com/p/fest/) Supports both Junit and TestNG assertThat(collection).hasSize(6).contains(frodo, sam);
  • 99. Assertions Misuse of assertions ▪ Manual assertions This practice misses out the main benefits of testing automation — the ability to continuously run the tests in the background without intervention ■ Multiple assertions ■ Redundant assertions Extra calls to an assert method where the condition being tested is a hard coded value assertTrue(“always true”, true) ■ Using the wrong assertions assertTrue("Object must be null", actual == null); assertTrue("Object must not be null", actual != null);
  • 100. Assertions What about void methods ? Often if a method doesn't return a value, it will have some side effect. There may be a way to verify that the side effect actually occurred as expected. Especially exception testing should not be forgotten.
  • 101. Assertions MyClass { public void addElement(String element, List<String> elements) { elements.add(element); } } public void testAddElement() { List<String> elements = new ArrayList(); assertEquals(0, elements.size() ); myClassTest.addElement(“test”, elements); assertEquals(1, elements.size() ); }
  • 102. Conclusion ▪ Always make sure your assertions are fully automated ▪ Junit assertions are ok for primitive types ▪ Hamcrest offers a lot of interesting matchers that allows you to assert more precise ▪ Unitils is a better alternative when comparing objects ▪ You can use them all together !
  • 103. The Red Line Goal of Testing What to Test Fixtures Mocks Assertions
  • 106. Exercises ! github: https://github.com/pijalu/utdemo ▪ Master: Default start ▪ Branches: Different solutions with different mocking framework… Don’t look ;-)
  • 107. Factoid - Model Fact ▪ Simple POJO ▪ Stores a fact ▪ It’s a string
  • 108. Factoid - Provider Provider interface: ▪ Provides a list of fact to a client ▪ int size(): Number of facts in the provider ▪ Fact getFact(index): Return a fact (0->size-1) ▪ Implementation: ▪ FileFactProvider ▪ Loads facts from a file. ▪ Line oriented
  • 109. Factoid- Service FactService interface: ▪ Returns a fact to client: ▪ Fact getAFact(): Return a fact ▪ Implementation: ▪ RandomFactService: ▪ Returns a random fact using a provider ▪ Uses Random ▪ Builds an array to avoid repetition/ensure all facts are returned
  • 110. Factoid - Main Factoid main class ▪ Loads a File with a (File)FactProvider ▪ Loads a (Random)FactService using created fact provider ▪ Calls FactService getAFact()
  • 111. Factoid - What to do ▪ Select the mocking framework you want ▪ EasyMock to start ! ▪ Check the FIXME in the existing code ▪ Fix as many as you can ! ▪ Be creative ▪ Look for other issues ;-)
  • 112. GO !
  • 113. Thanks for your attendance