Unit and integration tests are automated tests written by developers to test their code. Unit tests test individual functions or methods, while integration tests test how components work together. Tests are run automatically during continuous integration to check for failures and ensure code works as intended before deployment. Writing tests is important to catch bugs early and ensure code continues working properly over time as changes are made. Mocking is used in unit tests to simulate interactions between code components without executing their actual implementation.
Lets break some code. In this workshop we will be going over some of the fundamental concepts of software testing and take a hands on approach to writing Unit and Integration tests. We will cover topics such as mocking, stubbing, database patching and how this can all fit into a continuous integration environment like Jenkins.
A short presentation slide deck I gave to interns we have this summer of 2019 on (unit) testing in software development. This is not a code-centric slide deck and just looking at the slides loses some context without being there in person, or having discussions, etc.
Lets break some code. In this workshop we will be going over some of the fundamental concepts of software testing and take a hands on approach to writing Unit and Integration tests. We will cover topics such as mocking, stubbing, database patching and how this can all fit into a continuous integration environment like Jenkins.
A short presentation slide deck I gave to interns we have this summer of 2019 on (unit) testing in software development. This is not a code-centric slide deck and just looking at the slides loses some context without being there in person, or having discussions, etc.
An introduction to unit testing using Visual Studio, C#, xUnit.net, and Moq. What it is, what is isn't, why we don't do it, how to design for testability, what to test, test driven development, unit testing frameworks, mocking libraries, how to get started.
The presentation contains a definition and survey of the benefits of Unit Testing, and a little coding example to get the feeling of Unit Testing using JUnit, EasyMock and XMLUnit.
An introduction to unit testing using Visual Studio, C#, xUnit.net, and Moq. What it is, what is isn't, why we don't do it, how to design for testability, what to test, test driven development, unit testing frameworks, mocking libraries, how to get started.
The presentation contains a definition and survey of the benefits of Unit Testing, and a little coding example to get the feeling of Unit Testing using JUnit, EasyMock and XMLUnit.
Software testing
Developers Belief on Software Testing
Developers Responsibility for testing
Test writing methods
State based testing
Behavioural/interaction based testing
Writing a Testable Code
Flaw 1 - Constructor does Real Work
Flaw 2 - API lies about it's real dependencies
Flaw 3 - Brittle Global State & Singletons
Testing Frameworks and tools for Java...
Mockito and PowerMock...
Testing Models
Stubs Based Testing Model
Mocked Objects Based Testing Model
JUit 4.+ and TestNG
https://www.adroitlogic.com
https://developer.adroitlogic.com
Test-Driven Development is about approaching software development from a test perspective and knowing how to use the tools (e.g. JUnit, Mockito) to effectively write tests.
Source code examples @...
https://github.com/codeprimate-software/test-driven-development
Unit tests give developers and testers a quick way to look for logic errors in the methods of classes in Visual C#, Visual Basic, and Visual C++ projects. A unit test can be created one time and run every time that source code is changed to make sure that no bugs are introduced.
This workshop is about testing the right way. Get a clear view on how to test your code in an efficient and useful way!
This first testing-related workshop is about all aspects of unit testing. Integration testing and TDD will have their own dedicated workshops.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
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
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
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!
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
Intro To Unit and integration Testing
1. Unit & Integration Testing
Infusion Bootcamp 2017
Paul Churchward, FRM
Team Lead
2. ABOUT ME
• Team Lead based in Toronto
• With Infusion 2 years
• Background in finance (FRM, CSC)
• Stack: Java, Ruby
• Companies worked for
3. Developers code UNIT and INTEGRATION tests which
run automatically to test their software.
compares expected behaviour with actual behaviour
Unit and integration tests are part of the project source
Written by developer, not QA
Tests are executed automatically as part of continuous integration or by local builds, not by QA
Failures are reported (web dashboard/email/slack) and cause the build to abort
Fix failures by changing the code (sometimes, the test needs to be changed)
Fixing test failure raised by continuous integration is developer’s top priority b/c this holds up the team.
4. Verify logic works as intended
Simulate how code behaves under different circumstances (e.g. negative testing)
Ensure logic continues to works as designed after you’ve written
Not alone! Unit and integration testing is the first line of defense against bugs, not QA.
In a continuous delivery setup, unit & integration tests are your only line of defense, there is
no QA. When code passes the automated tests, it is automatically deployed to prod.
ISN’T TESTING QA’S JOB?
WHY WRITE A TEST?
5. A unit test tests the smallest unit of a program
produces expected behaviour.
A unit test typically tests a single method / function
Tests the method produces expected behaviour under different circumstances
Typical unit test will invoke a single method and test it produces expected output / right behaviour
6. Method’s return value is compared against the expected output for the input fed to it
Method invokes a service the expected number of times with the expected arguments
Note, we wouldn’t test the service’s output here. It should have its own test.
This is a key unit testing concept. Each test tests the bare minimum.
Method does not invoke a service when passed certain arguments
Method saves to database only when its call to Service-A returns true
Note, we wouldn’t test database was updated, only that the database service
in our code was called. This is a key unit testing concept. Don’t talk to external
services.
Examples of testing expected behaviour in a unit test:
7. An integration test tests components work together to
produce expected behaviour.
Scope goes beyond the innerworkings of a single method / function
Tests collaboration between components, taking it further than a unit test
For it to be an integration test, a “boundary” must be crossed
-> More than one component must be tested.
e.g. calling another class or calling an external service
Purpose is to test behaviour of external services like databases and other APIs
Number of unit tests outweigh integration tests -> Integration tests are much slower because
they talk to file systems / external APIs / databases.
8. UNIT TEST EXAMPLE:
(Let’s do this in pseudo code first)
When checkUserExists() on the UserDAO is invoked, force it to return false
When the addUser() method on UserService is invoked with the argument "FOO“ then:
Assert checkUserExists() on the UserDAO is invoked only once with the parameter "FOO"
Assert saveUser() on the UserDAO is invoked only once with the parameter "FOO"
Notice, we’re not testing the state of the database, only that we attempted to update the database. By
only testing the behaviour of the method, without testing anything outside the method we have
created a unit test. If we went further and tested the state of the database, we would have an
integration test.
This does not invoke the methods on the UserDAO or call out to the DB, it simply checks it should be
called. That would be out of scope for a unit test. This is achieved by using a mocking library (we’ll talk
about that later) which blocks actually invoking designated parts of the code we don’t want to be run
during the test.
9. INTEGRATION TEST EXAMPLE:
(Let’s do this in pseudo code first)
When the addUser() method on UserService is invoked with the argument "FOO“ then:
Assert getUser("FOO") on UserDAO returns a valid user with the username "FOO"
Notice, we’re testing the state of the database here. The test adds a user and then tests we get the
expected user back from the database when we query for it through our DAO. We’re not preventing the
code invoking any service (mocking). This is an integration test.
Build expected report
When the generateAndSave() method on ReportService is invoked, capture it’s report ID.
Assert retrieveReport("S3") on ReportService returns a report matching the expected report.
This test invokes the ReportService to generate a report and save it to Amazon S3. We test the code by retrieving the
report from S3 and comparing against one we already have. It should match. We’re not just testing the report itself
here, but that ReportService can read and write to Amazon S3 as expected. This makes it an integration test.
ANOTHER EXAMPLE:
10. Consider this example …
You write a report for another system to consume and the columns must be in
alphabetical order.
public void generateReport() {
List<String> columns = columnFactory.getColumns();
FooBarReport report = reportService.generateReport(ReportType.FooBar);
publishReportToS3(report);
}
Output:
FooBar Report
2015-03-18 13:00
================
A|B|C|D|E|F
2|6|2|4|2|6
1|3|5|9|11|
==
2 rows
I WISH I WROTE A (UNIT) TEST!
11. … 5 months later an accidental change is made to ColumnFactory causing it to spit out
columns in reverse alphabetical order and is pushed to production.
Your report now looks like this:
Output:
FooBar Report
2015-08-18 13:00
================
F|E|D|C|B|A
6|2|4|2|6|2
|11|9|5|3|1
==
2 rows
... The system consuming this report fails to read it and blows up in production
A unit test would have caught this right away.
12. WHAT TO UNIT TEST:
Method return value matches expected value (or null)
Method invokes a method of another classes the expected number of times.
Example: if your method calls UserDAO.save(), test that save() is only called once
Method doesn’t invoke method of another class.
Example: if you method should only call UserDAO.save() if the user doesn’t already exist, test for an existing
user and make sure UserDAO.save() is not called.
Method throws a specific exception
Example: if your method throws an CannotProcessException when a null userId , test that passes a null
and expects CannotProcessException to be thrown. If it were to throw IOException instead (or no
exception at all), that would be considered a failure.
13. MOCKING
In a unit test, we do not care about testing things outside of our method: e.g:
state of database changed by our method, state of file on file system, state of
another class invoked by our method.
We go a step further and prevent our method from changing the state or
databases, file systems and other classes. We use mocking to do this.
Mocking allows us to create fake (mock) instances of classes that we can
manipulate to make our test easier.
Mocking can render a class inert (calling its methods do nothing), or we can
specify the behaviour we want to happen when we call a specific method
Mocking is not used in an Integration test. That would defeat the purpose.
14. EXAMPLE:
Let’s write a unit test for this method in UserService
public void addUser(UserDAO dao,
Configuration config,
Connection conn,
String userName) throws BadArgException {
if(conn == null || config == null) {
throw new ConfigurationException();
}
dao.init(config, conn);
if(dao.userExists(userName)) {
throw new BadArgException()
}
dao.saveUser(userName);
}
15. EXAMPLE:
Components of the test:
Provide non-null instances of Configuration, Connection, UserDAO and a username String
Force UserDAO.checkUserExists() to return false -> Without talking to the database
Verify UserDAO.saveUser() is invoked only once -> BUT don’t write to the database
We will use Mockito (Java Mocking library) to “mock” UserDAO. This will:
> Preventing its methods from actually executing their code
> Allow us to force UserDAO.checkUserExists() to return false
> Allow us to count the number of times UserService.addUser() will call
UserDAO.saveUser() when we execute it in the test.
We will use Mockito to mock Configuration and Connection so that we get non null instances but
don’t have to create them (let’s assume it takes a fair bit of code to create these)
16. EXAMPLE:
public class UserService {
@Test
public void addUser_withRegualrUser_callsSaveUserOnce(){
UserDao dao = mock(UserDao.class);
Configuration config = mock(Configuration.class);
Connection conn = mock(Connection.class);
String user ="FOO";
UserService service = new UserService();
addUser(dao, config, conn, user);
verify(dao.saveUser(user), 1);
}
}
17. Test Driven Development advocates writing tests
BEFORE writing the code.
This forces you to plan how the component will work before you start coding it.
18. BEWARE of tests that don’t test anything
Not uncommon for people to write “tests” to invoke parts of the code outside
the normal flow. These so called tests don’t do any testing! A “test” that
simple invokes code but does not test it against expected behaviours is not a
test!
If a test does not compare expected behaviour with actual behaviour, it is not
a test. These are surprisingly common in the real world.
19. Multiple testing frameworks to chose from in each language. Here are a few
Java:
Junit, TestNg
C#:
Nunit
Ruby:
Rspec, FactoryGirl
Multi Language:
Cucumber (behaviour driven testing)
Tools