This presentation introduces the key testing concepts of the PHPUnit testing framework. It discusses unit testing, test cases, fixtures, stubs, mocks, and best practices for organizing and running tests. The presentation emphasizes that unit testing isolates and tests the smallest parts of an application to find errors, facilitate refactoring, and enable automated testing. PHPUnit allows writing tests for PHP code and provides features like data providers, exception handling, and code coverage reports.
phpunit is testing framework for php testing.
A browser is able to give the syntax error but what if in case of some logical error.
Phpunit testing enables you to check your logic.
It is fully object oriented framework.
It also can be enabled in Netbeans.
you can find the option of phpunit testing in Netbeans
phpunit is testing framework for php testing.
A browser is able to give the syntax error but what if in case of some logical error.
Phpunit testing enables you to check your logic.
It is fully object oriented framework.
It also can be enabled in Netbeans.
you can find the option of phpunit testing in Netbeans
Finally, easy integration testing with TestcontainersRudy De Busscher
Integration testing is always a difficult area. You need to make sure that all system are connected, data is correctly initialised for each run and test runs do not interfere with each other.
You can do integration testing today, but sometimes these tests are flaky for various reasons or they cannot cover all the cases that you would like to test.
With the Testcontainers project, this issue can be a thing of the past. It allows you to create reliable integration tests covering a wide range of scenarios like database usages, micro services interaction and GUI testing. One of the important factors for the success of this framework is the usage of Docker containers to create a reproducible environment for the test.
JUnit: A unit testing framework that is extensively used to test the code written in Java.
Unit testing is a type of software testing.
Software testing: The process of examining whether the software and its components meet the specified requirements
Other types of software testing are as shown.
Hearts Of Darkness - a Spring DevOps ApocalypseJoris Kuipers
In this talk Joris shares several real-life failure cases concerning running Spring applications in production. Examples include services being killed because of health check issues, Micrometer metrics getting lost, circuit breakers never closing after opening, OOM errors caused by unbounded queues and other nightmarish scenario’s. Not only will you come to understand how these problems could sneak through staging to make their way to production, you will also be given practical tips on how to avoid these things from happening to your own applications. Otto von Bismarck famously said “Fools say that they learn by experience. I prefer to profit by others’ experience”. Don’t be a fool, and profit by viewing this talk!
SOLID : les principes à l’origine du succès de Symfony et de vos applicationsVladyslav Riabchenko
SOLID est un acronyme représentant cinq principes de bases de la programmation orientée objet permettant le développement de logiciels fiables, évolutifs et robustes. Le framework Symfony est un excellent support pour illustrer chacun de ces principes. Nous verrons ainsi que SOLID est à l’origine de sa flexibilité, sa fiabilité mais aussi de sa maintenabilité et son évolutivité. Nous verrons également comment appliquer ces principes pour améliorer son code métier et perfectionner l’architecture de son application.
Slides for my talk at General Assembly's Web Dev bootcamp. Covers the motivations behind software testing, some theoretical background and hands-on exercises. Final challenge is testing a real-world like Node.js API using Mocha & Chai.
First Section:
Continuous Delivery as a software engineering approach.
(This is beneficial for Project Managers, DEVs & QAs.)
1. Projects Case Studies to explain why you should adopt Continuous Delivery.
2. Advantages & Reasons for releasing software more frequently.
3. How to make a Reliable / Production Ready Software.
4. Ingredients of Continues Delivery.
5. Tools/ approaches to choose while using Continues Delivery Methodology.
Second Section:
Technical side of Continuous Delivery.
(This is more beneficial for DEVs/ QAs than Project Managers.)
1. Testing a Software.
2. Measuring Code Quality / Analytic to visualize teams performances.
3. Tools: Code Syntax Checker, Testing Framework, Build Automation, Automated Reporting/ Analytic Dashboard.
4. Continuous Delivery Automation over Cloud using Travis CI - Live demonstration.
Third Section:
1. Sample Projects for audience to adopt right tools for development, testing & deployments.
2. Q&A.
-------------------------------------------------
By Waqar Alamgir http://waqaralamgir.tk
Finally, easy integration testing with TestcontainersRudy De Busscher
Integration testing is always a difficult area. You need to make sure that all system are connected, data is correctly initialised for each run and test runs do not interfere with each other.
You can do integration testing today, but sometimes these tests are flaky for various reasons or they cannot cover all the cases that you would like to test.
With the Testcontainers project, this issue can be a thing of the past. It allows you to create reliable integration tests covering a wide range of scenarios like database usages, micro services interaction and GUI testing. One of the important factors for the success of this framework is the usage of Docker containers to create a reproducible environment for the test.
JUnit: A unit testing framework that is extensively used to test the code written in Java.
Unit testing is a type of software testing.
Software testing: The process of examining whether the software and its components meet the specified requirements
Other types of software testing are as shown.
Hearts Of Darkness - a Spring DevOps ApocalypseJoris Kuipers
In this talk Joris shares several real-life failure cases concerning running Spring applications in production. Examples include services being killed because of health check issues, Micrometer metrics getting lost, circuit breakers never closing after opening, OOM errors caused by unbounded queues and other nightmarish scenario’s. Not only will you come to understand how these problems could sneak through staging to make their way to production, you will also be given practical tips on how to avoid these things from happening to your own applications. Otto von Bismarck famously said “Fools say that they learn by experience. I prefer to profit by others’ experience”. Don’t be a fool, and profit by viewing this talk!
SOLID : les principes à l’origine du succès de Symfony et de vos applicationsVladyslav Riabchenko
SOLID est un acronyme représentant cinq principes de bases de la programmation orientée objet permettant le développement de logiciels fiables, évolutifs et robustes. Le framework Symfony est un excellent support pour illustrer chacun de ces principes. Nous verrons ainsi que SOLID est à l’origine de sa flexibilité, sa fiabilité mais aussi de sa maintenabilité et son évolutivité. Nous verrons également comment appliquer ces principes pour améliorer son code métier et perfectionner l’architecture de son application.
Slides for my talk at General Assembly's Web Dev bootcamp. Covers the motivations behind software testing, some theoretical background and hands-on exercises. Final challenge is testing a real-world like Node.js API using Mocha & Chai.
First Section:
Continuous Delivery as a software engineering approach.
(This is beneficial for Project Managers, DEVs & QAs.)
1. Projects Case Studies to explain why you should adopt Continuous Delivery.
2. Advantages & Reasons for releasing software more frequently.
3. How to make a Reliable / Production Ready Software.
4. Ingredients of Continues Delivery.
5. Tools/ approaches to choose while using Continues Delivery Methodology.
Second Section:
Technical side of Continuous Delivery.
(This is more beneficial for DEVs/ QAs than Project Managers.)
1. Testing a Software.
2. Measuring Code Quality / Analytic to visualize teams performances.
3. Tools: Code Syntax Checker, Testing Framework, Build Automation, Automated Reporting/ Analytic Dashboard.
4. Continuous Delivery Automation over Cloud using Travis CI - Live demonstration.
Third Section:
1. Sample Projects for audience to adopt right tools for development, testing & deployments.
2. Q&A.
-------------------------------------------------
By Waqar Alamgir http://waqaralamgir.tk
Strategy-driven Test Generation with Open Source FrameworksDimitry Polivaev
Test suites for complex software systems contain thousands of test cases. Keeping track on the test coverage and changing the test suite as the system requirements evolve can consume significant efforts. The tutorial introduces and demonstrates an effort saving technique for developing, controlling and modifying test suites in agile, efficient, scalable and flexible way. The technique allows complete and explicit control over test amount, test depth and test coverage. It also makes possible to avoid code duplication in the non-generated test artifacts.
This technique allows generation of complete test suites given a specification describing test categories, test flow variations, test input data variations and requirement coverage criteria. All these kinds of data are commonly referred to as test properties. Their dependencies and variations are defined in test strategies.
The test strategies are expressed in a test strategy DSL which allows to express complex dependencies in a concise and easily understandable way. Behind the scene there is a rule engine generating test property value combinations from the test strategy definitions. The test suites containing independently executable test cases can be generated in any programming or scripting language or in a textual form. The generator uses a generic and an algorithm for mapping of test properties to the test scripts based on property naming conventions. For automatic test case execution a separate test driver component containing definition of single test steps referenced by the strategy should be written specifically in the chosen test script language.
All tools used for strategy-driven test generation are freely available under open source licenses.
Presentation to Craft CMS Meetup group in Charlotte, NC USA on November 13, 2019. Topic revolves around testing within the Craft framework using Codeception, as well as testing emails with Mailtrap and other types of tests. ~30 min read.
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.
Test Driven Development, or TDD, is the mainstream in many areas of software development, but what about the database? In this session, we explore TDD, the benefits of automated testing, and how testing data projects differs from other types of development. We introduce the tSQLt testing framework and demonstrate its use with a live coding example. Finally, we will discuss some lessons learned in doing TDD with SQL Server.
Originally presented by Steve Fibich and David Moore at Richmond SQL Server Users Group on January 11, 2018
Let's dive deeper into the world of ODC! Ricardo Alves (OutSystems) will join us to tell all about the new Data Fabric. After that, Sezen de Bruijn (OutSystems) will get into the details on how to best design a sturdy architecture within ODC.
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
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.
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.
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.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
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.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
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
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.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
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.
4. What is Software Testing?
Testing is the process of executing a program with intent
of finding errors (The art of software testing – Glenford J.Myers)
4
Our program
The output
is correct?
I1, I2, I3,
…, In, … Expected results
= ?
Obtained results
“Inputs”
- No code inspection - No code analysis
- No model checking - No bug fixing
- No debugging
5. Level of testing
KiSS Concept
Unit Testing
Integration Testing
Functional Testing
System Testing
Load/Stress Testing
User Accepted Testing
Regression Testing
Programmer
Tester
6. Testing Techniques
Functional Testing
(Black box)
Select test cases based
on the requirement or
design specification
Emphasize on the
external behavior of
software
Structural Testing
(White box)
Select test cases based
on the implement of
software
Emphasize on the internal
structure of software
KiSS Concept
8. Process of testing
KiSS Concept
Test
cases
Design test
cases
Prepare test
data
Run program
with test data
Test
data
Test
results
Test
reports
Compare
results to test
cases
10. What is unit testing?
KiSS Concept
“In computer programming, unit testing is a method by which
individual units of source code are tested to determine if they
are fit for use. A unit is the smallest testable part of an
application.” (Wikipedia)
A “unit ” is the smallest testable part of an application: a
function or class method.
14. Benefit of unit testing
Long term of saving time and money
KiSS Concept
15. When do you write the test?
Focus on requirements
Thinking about how to
code will be consumed
Stop coding when meet
requirement
Harder initially
Focus on code
Thinking about algorithm
More refactoring
Easier initially
KiSS Concept
Before coding(TDD) After/During coding
16. How do I test?
Isolate with the code being tested
Short, simple, fast, readable
No conditional logic or loop (if, switch, while)
One test should be one behavior
KiSS Concept
18. Introduction
KiSS Concept
Is a unit testing framework written in PHP, created by
Sebastian Bergmann.
Part of the xUnit family of testing frameworks.
Integrated/supported
• Zend Studio
• Zend Framework
• Symfony
• Doctrine
19. Installation
KiSS Concept
Install with PEAR:
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
Update:
pear upgrade phpunit/PHPUnit
Xdebug:
sudo apt-get install php5-xdebug php5-dev
Set include path in /etc/php5/cli/php.ini
include_path = “.:/usr/share/php”
20. Definitions
KiSS Concept
Test suite
Test suite
Test case
setUp()
testMethod
tearDown()
/*
*
*@annotation
*/
testMethod(){
assertion
}
Report
Test case
setUp()
testMethod
tearDown()
/*
*
*@annotation
*/
testMethod(){
assertion
}
Code coverage
Logging
22. Running test
KiSS Concept
Go to command line and run:
phpunit /path/to/file/test.php or phpunit classname
/path/to/file/test.php
23. Running test
Command line
IDE
Zend Studio
NetBean
Continuous Integration
phpUnderControl
Cruise Control
KiSS Concept
24. Result
OK: all tests are successful
FAILURES: test is fail or error
Result of each test:
• . test succeeds
• F an assertion fails
• E an error
• S test has been skipped
• I test is marked as being incomplete or not yet
implement
KiSS Concept
26. Data provider
Is a method that returns an array of values to use in a test.
Makes tests shorter and more concise.
Data provider can use array or file csv.
KiSS Concept
33. Fixtures
Is constructor method and destructor method in test case
PHPUnit supports 2 methods:
• setUp(): the function run when test methods start to
run
• tearDown(): the function run after test methods end
KiSS Concept
38. Test double
KiSS Concept
MyClass
myMethod()
{
…other Method
…
}
Database Mock
File system Mock
Web service Mock
MyClassTest
testMyMethod()
{
…
…
}
Set mocks
Solution: use copy object Test double
return fixed value
39. Stub and Mock
Set method return
values
Test state
Check method calls
Check arguments used
Test interactions
KiSS Concept
Stub Mock
42. Database testing
Set up database connection.
Set up initial dataset.
Provide methods to get dataset from database.
Provide methods to compare two datasets.
Type of dataset
Flat XML
XML
CSV
MySQL dump
KiSS Concept
43. Organizing
Allow to organize tests to test suite to run one time
Use file system:
All test files end with „Test‟.
Organize directory structure.
Use configuration file: phpunit.xml
KiSS Concept
46. Code Coverage
KiSS Concept
Help to see what are executed when the tests are run.
Help to find code that is not yet tested.
Help to measure testing completeness.
48. Code Coverage
KiSS Concept
Red: code is not executedGreen: code is executed
Test cases cover this line code
Grey: dead code
Note: dead code is source code which is executed but whose result is never used.
52. References
PHPUnit manual
Training course PHPUnit – Nick Belhome,2010
Unit Testing with PHPUnit – Michelangelo van Dam
Ini2it Unit Testing after ZF 1.8 - Michelangelo van Dam
PHPUnit From Zero To Hero – Jeremy Cook
PHPUnit & Continous Intergration – AlexMace
Advanced PHPUnit Testing – Mike Lively
Practical PHP Testing Patterns
http://framework.zend.com/manual/1.12/ru/zend.test.phpunit.db.html
KiSS Concept
- Kiểm thử phần mềm là quá trình thực thi một hệ thống phần mềm để xác định xem phần mềm đó có đúng với đặc tả không và thực hiện trong môi trường như mong đợi hay không. - Mục đích của kiểm thử phần mềm:Tìmralỗichưađượcpháthiệnmộtcáchsớmnhất, hiệuquảnhấtĐảmbảolỗiđãđượcsửa- Kiểmthửphầnmềmkhôngkiểmtra code, khôngkiểmtra database, model, không debug, không fix bug
Unit testing : làkiểu test kiểmtra code xemliệuchứcnăngnóđangthựchiệncóđúngcách hay khôngtheonhưyêucầu.Integration testing : làkiểu test kiểmtraliệutấtcảcác module làđượckếthợphoặcchưakếthợplạicùngvớinhauthựchiệncôngviệccóđạtđượckếtquảnhưtàiliệuyêucầuđãđượcxácđịnh (do mỗilậptrìnhviênthựchiệntrêncác module khácnhau. Khihọhoànthànhđoạn code củahọ, nhómquảnlýcấuhìnhrápchúnglạivớinhauvàchuẩnbịbiêndịch. Các tester cầnchắcrằngcác module nàybâygiờđãđượckếthợpvàlàmviệctheonhưyêucầu - tứclàphải test theonhưyêucầu).- Functional testing : làkiểu test liệumỗivàmọichứcnăngcủaứngdụngđóđanglàmviệccónhưyêucầucủatàiliệu. Nólàkiểu test chínhmà 80% côngviệc test đượcthựchiện. Trongkiểu test nàythìcáctestcaseđượcthựchiện (hoặcthihành).- System testing:Khi tester hoànthànhcôngviệc test (các tester test ứngdụngtrongcácmôitrường test, nghĩalàhọ test vớidữliệu test, không test trêndữliệuthật), ứngdụng (phầnmềm) phảiđược test trênmôitrườngthật. Nónghĩalàgì, tứclàkểtừkhicác tester test nótrongmôitrường test vớidữliệu test, chúng ta phảichắcchắnrằngứngdụnglàmviệctốttrongmôitrườngthậtvớidữliệuthật. Trongmôitrường test, mộtvàiđiềukhôngthể test hoặcthaotácgiả. Tấtcảsẽkhácnhauvàcơsởdữliệukhácnhau, mộtsốthaotáccóthểkhônglàmviệcnhưmongđợikhiứngdụngđượcchuyểntừmôitrường test sang môitrườngsảnphẩm (test enviroment to production environment).- Load testing ? Làkiểu test kiểmtrathờigianđáplạingườidùngvớiứngsốlượngngườidùngbấtkỳtrongmộtngữcảnhnàođócủacùngmộtứngdụngtạicùngmộtthờiđiểm.- Stress testing làgì? Làkiểu test kiểmtrathờigianđáplạingườidùngvớiứngsốlượngngườidùngbấtkỳtrongnhiềungữcảnhkhácnhaucủacùngmộtứngdụngtạicùngmộtthờiđiểm.- Performance testing làgì? Trongloại test này, ứngdụngđược test dựavàosứcnặngnhưsựphứctạpcủagiátrị, độdàicủađầuvào, độdàicủacáccâutruyvấn...Loại test nàykiểmtrabớtphầntải (stress/load) củaứngdụngcóthểđượcchắcchắnhơn.- User acceptance testing làgì? Trongkiểu test này, phầnmềmsẽđượcthựchiệnkiểmtratừngườidùngđểtìmranếuphầnmềmphùhợpvớisựmongđợicủangườidùngvàthựchiệnđúngnhưmongđợi. Tronggiaiđoạn test này, tester cóthểcũngthựchiệnhoặckháchhàngcócác tester củariênghọđểthựchiện.- Regression testing làgì? Khimộtchứcnăngmớiđượcthêmvàophầnmềm, chúng ta cầnchắcchắnrằngphầnchứcnăngmớiđượcthêmvàokhôngpháhỏngcácphầnkháccủaứngdụng. Hoặckhilỗiđãđượcchỉnhsửa, chúng ta cầnchắcchắnrằnglỗichỉnhsửakhôngpháhỏngcácphầnkháctrongứngdụng. Để test điềunàychúng ta thựchiệnkiểu test lặpđilặplạigọilà test hồiquy.
Functional Testing: kiểmthửchứcnăng hay còngọikiểmthửhộpđen (blackbox)Black box làloại test mà tester đưagiátrịđầuvàovàkiểmtragiátrịđầurakhôngquantâmbêntronghoạtđộngnhưthếnào.Chủyếukiểmtragiaodiện, chứcnăngthiếu hay không, vv-Dựavàođặctảyêucầumàđưaracác test case: vìlàloại test chỉquan tam hệthốngphầnmềmcóhoạtđộngđúngnhưtrongyêucầu hay không, khôngquantâmbêntronglàmnhưthếnào-Chỉchútrọnghành vi bênngoàicủaphầnmềm.Structural Testing: kiểmthửcấutrúc hay còngọikiểmthửhộptrắng(white box)White box làloại test mà developer dựavàomã code củamìnhmàđưaracác test case.Test dựavàođiềukhiển logic (if else switch), điềukhiểnvònglặp (for while), cấutrúcdữliệubêntrongDựavàoviệcthựcthicủaphầnmềmmàđưaracác test caseChútrọngcấutrúcbêntrongcủaphầnmềm
Giátrịđầuvào: 2 đồngxu, gõcâyđũa ma thuậtGiátrịđầura: con thỏBlack box: khángiả chi nhìnthấyảothuậtgiabỏ 2 đồngxu, vàgõcâyđũavàocáinón, và con thỏxuấthiệnWhite box: khinhậnđược 2 đồngxuvàthấycáinónbịgõ, ngườibêntrongđưa con thỏchoảothuậtgia
Unit testinglàphươngpháp test đơnvịcủa source code đểxácđịnh code đểcóhoạtđộngđúngnhưmongđợikhông.Một unit cóthểlàmột class hoặchàmcủachươngtrình
Có 2 giaiđoạnchính:Trướckhi code hay còngọilàphươngpháp TDD(Test Driven Development: từviệc test dẫnđếnviết code để past test đó) - Tậptrungvàoyêucầucủachươngtrình - Nghĩđếnviệcviết code sẽđượcsửdụng - Ngưng code khiđạtđượcyêucầucủachươngtrình - KhókhănlúcbắtđầuSaukhi code xonghoặctronglúc code - Test chủyếuvàonhữngphầnđã code - Nghĩvềthuậttoánvà logic - Thayđổi code nhiềuhơn - Dễlúcbắtđầu
- Code test phảiđộclập, cáchbiệtvới code được test - Code test phảingắngọn (khoảng 10 dòng), đơngiản, nhanhvàdễđọc. - Khôngsửdụngcáccấutrúcđiềukhiểnvàvònglặptronghàm test. Mỗicâulệnh if else nêntáchthànhnhiềuhàm test khácnhau, mỗihàmlà 1 trườnghợp test - Mộthàm test chỉnên test cho 1 trạngthái. VídụtestFormAcceptValidData
PHPUnit là 1 framework viếtbằng PHP bởi Sebastian Bergmann.ThuộchọxUnit framework. xUnit frameworks: these unit testing frameworks are called the xUnit frameworks because their names usually start with the first letters of the language for which they were built.You might have CppUnit for C++, Junit for Java, Nunit for .NET.ĐượctíchhợpvàhỗtrợbởiZend Studio, Zend framework hay Symfony framework, doctrine
Chạybằng command line: phpunitđườngdẫnđến file testChạybằng IDE: - Zend: trướchết import library vào project: Project -> Properties -> PHP Include Path -> tab Libraries -> click nút Add Library -> chọn PHPUnit 3.x -> OK. Đểchạynhấpchuộtphảilên file -> Run As ->PHPUnit, hiệnkhungkếtquảphpunit - NetBean: kiểmtraphpunitđãthêmvàochưa: Tool -> Option -> tab PHP -> tab Unit Testing -> kiểmtrađườngdẫncủaphpunit “/usr/bin/phpunit”Đểchạy file -> Run -> Test file -> chỉthưmụcchứa file test -> OKĐểchạy test suite: right click tên project -> Properties -> PHPUnit , chọn file bootstrap nếucó, chọn file configuration xml nếucó, chọn check box chạytấtcả file cótênlà Test -> OKĐểhiện coverage report: right click tên project -> Code Coverage -> show reportChạybằng Continuous Integration (CI): tíchhợpliêntụcContinuous Intergration hay CI làmộtmôitrườnghỗtrợpháttriểnphầnmềmcóchứcnănggiúpcácthànhviêntrong team tíchhợp (integrate) côngviệccủahọmộtcáchthườngxuyên, liêntục. Mỗiđiểmtíchhợpsẽđượckiểmtra (verified) bởimột qui trình build và test tựđộngđểđảmbảopháthiệnsớmnhấtnhữnglỗiphátsinhtrongquátrìnhtíchhợpđó.Giảiphápnàythựcsựgiúpchocácnhàpháttriểnphầnmềmgiảmbớtcácvấnđềphátsinhtrongquátrìnhtíchhợpvàchophépcôngviệcpháttriểnphầntrởnênmềmnhanhchóngvàgắnkếthơn. CI baohàmmộtloạtnhữngquátrìnhđượcgắnkếtvớinhaunhư: automated build, coding standard check, static analysic, unit test, depoyingvàintergation test...
Cácchứcnăngchínhcủaphpunit - Test dependency - Data provider - Exception - Fixture - Double - Code coverage
Vớiviệc test thôngthường, để test 1 hàm, chúng ta truyềnvàothamsốsauđólấykếtquảtrảvề so sánhvớikếtquảchúng ta mongmuốn, sauđóxuất reportTest nhiềugiátrịđầuvào, viết code lậplạinhiềulần, mấtthờigianvìvậysửdụng data provider
Data provider cungcấpdữliệuđể test. Dữliệunàycóthểlàgiátrịthamsốtruyềnvàohàmhoặcgiátrịmongmuốntrảvề, v.v
Yêucầuđốivớiviệc test làcácthànhphầnphảiđược test riêngrẽvớinhauđểkếtquảcủathànhphầnkhôngbịảnhhưởngbởithànhphầnkhácvídụkhichúng ta gọiđến service đểlấykếtquảvàsauđólấykếtquảđểtínhtoántiếpchocôngviệccủachúng ta thìbắtbuộckếtquảtrảvềluônluônphảiđúngđểbiếtchắcnếu test củachúng ta bị fail là do code củachúng ta chứkhôngphải do service làmsai. Đểlàmđiềuđóđôikhichúng ta phảigiảlậpnhữngthànhphầnđóđểđảmbảo test đượccôlậpvàchínhxác. Việcgiảlập 1 đốitượngđượcgọilà test doubles.Ý tưởngcủa test double chỉgiảlập 1 phầncủa object, thườnglà 1 method nàođócần test chứkhônggiảlậptoànbộ object.Test double khôngphảithiếtkếmộtchotấtcảnêntùyvàotrườnghợpmàsửdụngcácloại double khácnhau. Test double cómấyloạisau:Dummy: là 1 object màđơngiảnđượcthông qua đểthỏamãncácphươngthứccầnkiểmtra. Nólà test double đơngiảnnhấtmàbạncóthểxâydựngStub cungcấpnhữngkếtquảđóngkhiđượcgọiSpy ghilạinhữnglầngọivàthamsốđểbạncóthểkiểmtrachúngsaunàybêntronghàm testMock giốngnhư Spy nhưngkiểmtralầngọingaylậptứcdựatheonhữnggìmàbạnđãđịnhnghĩatrướcđó. Nócũngcóthểcungcấpkếtquảđóng.Fake làsựthựcthimộtcáchđơngiảnnhấtcóthểcủamột object thậtchẳnghạnnhư DAO.Trongđóchúng ta chỉchú ý đặcbiệtđến Stub và Mock vìlà 2 đốitượngthườngdùng.Stub object làbảnsaocủamột object khácđượcchúng ta địnhnghĩatrướcvàtrảvề 1 kếtquảđóngcủamộtphươngthứctrong object đócũngđượcđịnhnghĩatrướcMock : điểmkhácnhaucănbảngiữa Stub và Mock là Mock khôngchỉgiảlập object màcònchokiểmtranhữnggìbạntruyềnchonóvàcáchbạngọinó.