Mocking allows testing components in isolation without dependencies like databases or file systems. It emphasizes single responsibility by allowing classes to behave consistently regardless of dependency implementations. Mockito provides mocking capabilities like stubbing mock methods to return values or exceptions and verifying mock method calls and arguments. It supports argument matchers, verifying call order and number of invocations, and spying to selectively mock certain methods of real objects.
Demonstrate some great aspects of Mockito. Made for Mockito v1.8.5.
All examples can be found @
https://github.com/dodozhang21/MockitoExamples
Ying Zhang (Dodo) http://pure-essence.net
Demonstrate some great aspects of Mockito. Made for Mockito v1.8.5.
All examples can be found @
https://github.com/dodozhang21/MockitoExamples
Ying Zhang (Dodo) http://pure-essence.net
Mockito vs JMockit, battle of the mocking frameworksEndranNL
(Original keynote slides can be found at https://github.com/Endran/PublicSlides)
For years the industry standard of mocking on the JVM has been Mockito. Mockito is a wonderful library that really speeds up your testing by allowing you to create mocks in a very simple way. That being said, it does have its drawbacks, for which different strategies need to be deployed to keep your code testable. The main drawbacks are statics and finals. Final classes cannot be mocked, nor final methods, and also static methods are a no-go. To work with these type of things we need to wrap it, and copy the signature in a non final, non static way.
I have a great adversity against statics, I've devoted an entire post about it, in short; It hides dependencies and brings so little convenience at the costs of its drawbacks. Finals on the other hand have purpose, it helps messaging the goal of a class or method. Java is one of the few languages where classes and methods are open/virtual by default and have to be closed/final by explicit action. In (for example) Kotlin, everything is final by default, if you do not want something to be final, you should use the open keyword.
No matter if you follow the principle of making things final, static or not, if you are using Mockito the decision has been made. This mocking framework demands that everything is non-final, demands that everything is designed to be extended, since it might need to be mocked away. We should be able to improve upon this, and by the name of this post, you should be able to guess which framework will save the day. JMockit will help us with our impediments, and will give some other nifty benefits as well!
Mastering Mock Objects - Advanced Unit Testing for JavaDenilson Nastacio
A high-level description of mock testing techniques and their implementation for the Java programming language.
This presentation specifically focus on the JMockit and JMock frameworks.
PVS-Studio analyzer is continuously improving, and the C#-code analysis module is developing most actively: ninety new diagnostic rules were added in 2016. However, the best way to estimate the analyzer's efficiency is to look at the bugs it can catch. It's always interesting, as well as useful, to do recurring checks of large open-source projects at certain intervals and compare their results. Today I will talk about the results of the second analysis of SharpDevelop project.
Mockito vs JMockit, battle of the mocking frameworksEndranNL
(Original keynote slides can be found at https://github.com/Endran/PublicSlides)
For years the industry standard of mocking on the JVM has been Mockito. Mockito is a wonderful library that really speeds up your testing by allowing you to create mocks in a very simple way. That being said, it does have its drawbacks, for which different strategies need to be deployed to keep your code testable. The main drawbacks are statics and finals. Final classes cannot be mocked, nor final methods, and also static methods are a no-go. To work with these type of things we need to wrap it, and copy the signature in a non final, non static way.
I have a great adversity against statics, I've devoted an entire post about it, in short; It hides dependencies and brings so little convenience at the costs of its drawbacks. Finals on the other hand have purpose, it helps messaging the goal of a class or method. Java is one of the few languages where classes and methods are open/virtual by default and have to be closed/final by explicit action. In (for example) Kotlin, everything is final by default, if you do not want something to be final, you should use the open keyword.
No matter if you follow the principle of making things final, static or not, if you are using Mockito the decision has been made. This mocking framework demands that everything is non-final, demands that everything is designed to be extended, since it might need to be mocked away. We should be able to improve upon this, and by the name of this post, you should be able to guess which framework will save the day. JMockit will help us with our impediments, and will give some other nifty benefits as well!
Mastering Mock Objects - Advanced Unit Testing for JavaDenilson Nastacio
A high-level description of mock testing techniques and their implementation for the Java programming language.
This presentation specifically focus on the JMockit and JMock frameworks.
PVS-Studio analyzer is continuously improving, and the C#-code analysis module is developing most actively: ninety new diagnostic rules were added in 2016. However, the best way to estimate the analyzer's efficiency is to look at the bugs it can catch. It's always interesting, as well as useful, to do recurring checks of large open-source projects at certain intervals and compare their results. Today I will talk about the results of the second analysis of SharpDevelop project.
Unit testing patterns for concurrent codeDror Helper
Getting started with unit testing is not hard, the only problem is that most programs are more than a simple calculator with two parameters and a returns value that is easy to verify.
Writing unit tests for multi-threaded code is harder still.
Over the years I discovered useful patterns that helped me to test multi-threaded and asynchronous code and enabled the creation of deterministic, simple and robust unit tests.
Come learn how to test code that uses concurrency and parallelism – so that the excuses of not writing unit tests for such code would become as obsolete as a single core processors.
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)Tech in Asia ID
Currently, Fandy is the mobile apps tech lead works for OLX Indonesia and has been working on both Android and iOS since Cupcake and iOS 2.x respectively. As a tech lead he is responsible for delivering software into production safely and quickly in a sustainable way.
***
This slide was shared at Tech in Asia Product Development Conference 2017 (PDC'17) on 9-10 August 2017.
Get more insightful updates from TIA by subscribing techin.asia/updateselalu
Secret unit testing tools no one ever told you aboutDror Helper
There are more to unit testing than using a unit testing framework – in order to succeed you want to use the right tools for the job. There are a few tools that almost no one talks about – some enabling creating of top-notch, robust unit tests. Some will help you run your tests better and faster.
In this session I’ll explain about the inevitable maintainability problems developers face when writing and maintaining huge unit testing suits and how unit level BDD, AutoMocking, and Continuous Execution can help take control over your tests.
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...solit
Виктор Короневич, Минск. Senior Software Test Automation Engineer with 3+ years of experience specializing in automation on Java, http://www.linkedin.com/in/agileseph
«Автоматизация тестирования сложных систем: mixed mode automated test case.» Использование Selenium + jUnit + Frank + custom java tools для тестирования Web + DB + Web Services + iOS. Development секция.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
2. Why do we need mocking ?
● To test your application components in isolation,
without a database, DNS server, SVN repository,
filesystem.
● Because a class should have one responsibility
only and a clean test should emphasize that.
● In a good encapsulated design, a class should
behave the same regardless of the
implementation classes of its dependencies.
3. A simple example of mocking
● You can mock concrete classes as well as
interfaces. This creates a proxy to the object.
LinkedList mockedList = mock(LinkedList.class);
when(mockedList.get(0)).thenReturn("first");
when(mockedList.get(1)).thenThrow(new RuntimeException());
● Calling a method on the object will either involve a
call to the real object...
mockedList.get(2);
● or it may involve a call that returns the mocked vale
mockedList.get(0); // will return "first"
4. Using Mockito for verification testing
● Create a mock using the mock() method or by
annotating an object with @Mock
List mockedList = mock(List.class);
@Mock List mockedList;
● Example of verifying method calls
mockedList.add("one");
mockedList.clear();
verify(mockedList).add("one");
verify(mockedList).clear();
5. Stubbing
● By default, for all methods that return a value, mock returns null, an
empty collection or appropriate primitive/primitive wrapper value.
● Stubbing can be overridden: for example common stubbing can go
to fixture setup, but the test methods can override it. Please note
that overridding stubbing is a potential code smell that points out
too much stubbing
● Once stubbed, the method will always return the stubbed value
regardless of how many times it is called.
● Last stubbing is more important - when you stubbed the same
method with the same arguments many times.
6. Argument Matchers
● Sometimes, when extra flexibility is required then you might
use argument matchers
when(mockedList.get(anyInt())).thenReturn("a");
when(mockedList.contains(argThat(isValid()))).thenReturn("a");
System.out.println(mockedList.get(999));
● You can also verify a call using an argument matcher
verify(mockedList).get(anyInt());
● If you are using argument matcher then all arguments have
to be provided by matchers.
verify(mock).someMethod(anyInt(), anyString(),
eq("third argument"));
7. Verifying exact number of invocations / at least x /
never
●The following two verifications work in the same way. We can
use times() to specify the number of invocations expected:
verify(mockedList).add("once");
verify(mockedList, times(1)).add("once");
●Verify that something never happened:
verify(mockedList, never()).add("never happened");
Verify that something happened at least n times:
verify(mockedList, atLeastOnce()).add("three times");
verify(mockedList, atLeast(2)).add("five times");
verify(mockedList, atMost(5)).add("three times");
8. Verification in order
List firstMock = mock(List.class);
List secondMock = mock(List.class);
//using mocks
firstMock.add("was called first");
secondMock.add("was called second");
//create inOrder object passing any mocks that need to be verified in order
InOrder inOrder = inOrder(firstMock, secondMock);
//following will make sure that firstMock was called before secondMock
inOrder.verify(firstMock).add("was called first");
inOrder.verify(secondMock).add("was called second");
● Verification in order is flexible - you don't have to verify all interactions one-by-one but only
those that you are interested in testing in order.
● Also, you can create InOrder object passing only mocks that are relevant for in-order
verification.
9. Making sure interaction(s) never happened on mock
Verify that method was never called on a
mock:
verify(mockOne, never()).add("two");
Verify that there were no interactions:
verifyZeroInteractions(mockTwo, mockThree);
10. Finding redundant invocations
● Using mocks:
mockedList.add("one");
mockedList.add("two");
verify(mockedList).add("one");
//following verification will fail
verifyNoMoreInteractions(mockedList);
11. Spy - Partial mocks
List list = spy(new LinkedList());
Enable partial mock capabilities selectively on mocks:
Foo mock = mock(Foo.class);
Be sure the real implementation is 'safe'.
//If real implementation throws exceptions or depends on specific
state of the object then you're in trouble.
when(mock.someMethod()).thenCallRealMethod();
//Impossible: real method is called so spy.get(0) throws
IndexOutOfBoundsException (the list is yet empty)
when(spy.get(0)).thenReturn("foo");
12. Capturing arguments for further assertions
ArgumentCaptor<Person> argument =
ArgumentCaptor.forClass(Person.class);
verify(mock).
doSomething(argument.capture());
assertEquals("John",
argument.getValue().getName());
14. Stubbing consecutive calls (iterator-style stubbing)
● Sometimes we need to stub with different return value/exception for the same
method call
when(mock.someMethod("some arg"))
.thenThrow(new RuntimeException())
● //First call: throws runtime exception: mock.someMethod("some arg");
● //Second call: prints "foo" System.out.println(mock.someMethod("some arg"));
● //Any consecutive call: prints "foo" as well (last stubbing wins).
System.out.println(mock.someMethod("some arg"));
● Alternative, shorter version of consecutive stubbing:
when(mock.someMethod("some arg")) .thenReturn("one", "two", "three")
15. Limitations
● Needs java 1.5+
● Cannot mock final classes, static or private methods - but this is
possible with PowerMockito.
● Cannot mock equals(), hashCode(). Firstly, you should not mock
those methods. Secondly, Mockito defines and depends upon a
specific implementation of these methods. Redefining them might
break Mockito.
● Spying on real methods where real implementation references outer
Class via OuterClass.this is impossible. Don't worry, this is
extremely rare case.