
寻找一个适合初学者的“入门”指南,同时也尽可能全面地包含丰富的真实案例场景,完全涵盖 Unit 的所有方面、细节、细节和集成测试 Python?是的,亲爱的,你来对地方了。
欢迎来到“Python 中的动手软件测试”!
如果您是自由职业者、大学生或软件工程师,在某些时候不可避免地不运行至少一些“探索性测试”脚本来检查和测试各种边缘案例,只是为了确保您的工作有多扎实,但是当某个组件发生故障时,事情开始走下坡路,要么你进入重构炼狱,要么你从头开始重新启动项目!在本课程中,我将向您展示多个案例场景,我们将拥有现有的代码库,以及我们将以代码方式从头开始构建的迷你项目,最重要的是我们将遵循系统的程序为每个案例场景分析和设计我们的测试用例,然后实施它们。
我的名字是 Ahmed Alhallag,我是一名软件工程师和助理讲师。我将带你经历一个密集的旅程,从软件测试背后的理论概念开始,直到最里面的部分,你将学习处理任何项目的最佳实践,在任何范式中设计和实现(程序和 OOP 包含在这个当然),无论从表面上看它有多大或多大。
作为软件开发人员,编写代码不应该是您的主要关注点,尤其是在当前时间点“工作”的代码。还需要考虑许多其他因素,例如
建模质量
您可能会想:“好吧,我有这个任务要实现,所以让我们开始吧!”,然后您立即跳到您最喜欢的 IDE 并开始编码。对于某些任务,也许这将是省时的事情,对于较大的任务,从长远来看,这最终会消耗你的时间,因为你会不断地在
封装此代码块,并重构该代码块,在开始工作时将敏感数据丢弃在脚本顶部后将其保存在 .env 文件中,序列化此输出,并将该输出保存到 json 文件中而不是一个基本的 txt 文件,创建一个中间件、一个 API 接口或某个控制器,你突然发现你需要执行一些操作,实现一个数据处理程序,因为代码变得如此冗余和交织在一起,改变了整个集合使用的数据结构,因此也改变了提前编写的整个处理逻辑!
看,前面的所有场景,只是我们在开发过程中经历的日常事件,如果你还没有遇到过任何一个,那是个好消息!我们将简要介绍一种通过分析(OOA)和设计(使用 UML 的 OOD)实现代码的系统方法,并借助我们将共同构建的迷你项目!
这显然不是本课程的重点,因此我们不会在这部分上花费太多时间,我们将在稍后实施时需要获得一个干净的代码库。
代码质量
在概念设计和建模的简要概念之后,我们将按照我们创建的指南(类图)来实现我们稍后将逐步测试的核心系统。我们将在大多数实现中使用面向对象编程 (OOP)。
您可能会问自己,为什么我们要在每个用例的实现上花费这么多时间?为什么不直接使用代码并开始编写测试用例呢?
这是一个有效的观点,但请听我说:我相信如果您想了解系统的来龙去脉,无论您是执行防御性/进攻性安全措施、设计 UI/UX、实现数据库层还是执行有些测试用例,您需要完全了解您正在使用的系统。
对于有经验的开发人员来说,他们绝对可以在任何时候加快步伐并开始实施他们的测试用例,但对于之前没有写过很多测试用例的人来说,或者在他们的旅程开始时,这将是一个麻烦!不知道究竟需要测试什么,甚至不知道如何或从哪里开始!
这是我在大多数给定案例场景中遵循的方法的基础,基本上我们将构建我们希望从头开始彻底测试的终端系统!
在简要介绍了代码/系统建模的最佳实践并手动实现这些系统之后,我们将深入测试,其中
我们将主要使用 Python 中的 unittest 框架,它是一个内置的易于使用的模块,可以尽快上手。
我们将开始以程序化方式(使用最基本的模块化方法;函数)来实现这个小项目。
然后,我们将如何为我们的程序代码设计和实施单元测试,方法是设置我们关于什么应该被定义为“单元”的协议条款,以及配置新的项目层次结构(文件夹树)。
我们将介绍一种最常用的测试方法;测试驱动开发,简称 TDD。
然后,我们将进行范式转变,进入 OOP 领域。我假设您在 OOP 方面有相当的背景,我们将简要回顾一下。(观看宣传/介绍视频)
我们将为我们创建的面向对象(类)编写单元测试,并更新我们的“单元”定义。
通过使用终端会话使用 Python 交互式调试器实时检查和调试单元测试,我们将了解您对命令行界面 (CLI) 的了解有多么有用。
我们将拥有真实数据,我们将学习如何在需要时对它们进行采样和/或伪造它们
我们将设计和实现相互关联的模块,我们还将设计和实现它们之间的关系。并且会知道通过这样做,需要执行另一个不同的添加层/类型的测试,即集成测试,以确保集成组件按预期工作。
我们会看到很多耦合的依赖关系,这将导致我们使用“Mocking”来完全隔离它们来执行我们的单元测试。
我们将学习如何处理中间代码或传递代码,因为有时不清楚是否应该测试它们。
我们将学习如何生成测试覆盖率报告(在 HTML 中)以及如何同时运行多个(单元和集成)测试。
最后,我们将对文件处理程序和操作(例如读取、写入等)以及常见的 stdout 和 stdout 函数(例如打印、输入)以及如何准确地测试它们以实现全面覆盖进行深入的演练。
An In-depth practical guide to manual unit and integration testing in Python with real-world case scenarios.
Published 07/2022
MP4 | Video: h264, 1280×720 | Audio: AAC, 44.1 KHz, 2 Ch
Genre: eLearning | Language: English + srt | Duration:22 lectures (9h 2m) | Size: 4 GB
What you’ll learn
Analyze existing code bases (& refactor them if needed), and design the needed test cases accordingly.
Perform manual unit and integration tests on Procedural code and Object Oriented code.
Learn how to perform Test Driven Development (TDD)
Perform test coverage and run multiple tests simultaneously.
Learn how to deal with boiler-plate code and pass-through methods/functions.
Utilize Pdb (Interactive Python Debugger) on run-time to inspect different test cases.
Learn how to effectively create mocks and when to do it based on various case scenarios,
Know how to fake/sample real-world data.
Gain a sneak-peak on best practices in OOA, OOD & OOP by implementing UML design schemes from scratch and write tests for the code base you created later on.
Requirements
Fair background in Python is a must.
Fair background in OOP in Python (specifically classes & object creation, classmethods, staticmethods, getters & setters). (don’t worry I take everything gradually in this course)
If you felt anything that you lack or do not understand, reach out to me, I will be available 24/7.
If you think you need more background on any of the side topics illustrated, you can find exactly the materials to get you started in my other courses.
Description
Looking for a beginner-friendly, ‘getting-started’ guide, that happens to ALSO be as comprehensive as possible with rich real-world case scenarios that COMPLETELY covers the all aspects, the ins-and-outs, the nits and grits of Unit and Integration testing Python? Yes dear, you are at the right place.
Welcome to “Hands-On Software Testing in Python” !
If you are a freelancer, a college student, or a software engineer, at some point it’s just inevitable to not run atleast some ‘exploratory testing’ scripts to inspect and test various edge cases, just to make sure how solid your work is, but things starts to go downhill when a certain component breaks down, it’s either you go into a refactoring purgatory, or you start the project again from scratch! In this course I will show you multiple case scenarios, where we will have existing code bases, as well as mini-projects that we will build from scratch in a code-along fashion, what matters the most is that we will follow a systematic procedure to analyze and design our test cases, for each case scenario, and then implement them.
My name is Ahmed Alhallag, I’m a Software Engineer and an Assistant Lecturer. I will take you through an intensive journey starting with the theoretical concepts behind Software Testing, up to the inner-most parts where you will learn the best practices in approaching any project, designed and implemented in any paradigm (Procedural & OOP are covered in this course), no matter how large or big it might seem from the surface.
Writing code isn’t supposed to be the main point of focus for you as a software developer, especially code that just ‘works’ for a current point of time. A bunch of other factors needs to be taken into consideration such as
Quality of modeling
You might think: “alright, I have this task to implement, so let’s just wing it!”, and you immediately hop on to your favorite IDE and starting coding. For certain tasks, maybe this would be the time-efficient thing to do, for larger one, this will eventually consume your time on the long run, because you will keep going back in forth in
encapsulating this block of code, and refactoring that block of code, saving your sensitive data in a .env file after it was thrown away at the top of your script when you started working, serializing this output, and persisting that output into a json file instead of a basic txt file, creating a middleware, an API interface or a certain controller that you suddenly found out that you need to perform some action, implement a data handler because the code became so redundant and intertwined, changing up the entire set of data structures used, which as a result, changes the entire processing logic written ahead of time as well!
See, all of the previous scenarios, are just daily events that we go through in our development journey, if you haven’t faced any of them yet, that’s good news! We will briefly cover a systematic way to implement our code via analysis (OOA) and design (OOD using UML), with the help of mini-projects that we will build together!
This is obviously not the focus of this course, so we won’t be spending much time on that part, we will take we need to get to have a clean code base later on when we implement.
Quality of code
After the brief concepts on conceptual designs and modeling, we will follow the guides (class diagrams) we created to implement the core system we will test bit by bit later on. We will be using Object Oriented Programming (OOP) for the majority of our implementations.
You might ask yourself, why would we spend THIS much time at the implementation of every use case? why not just take the code as it is and start writing test cases?
That’s a valid point, but hear me out: I believe that if your want to know the ins and outs of a system, whether you are performing a defensive/offensive security measure, designing a UI/UX, implementing a database layer, or executing some test cases, you need to be FULLY and THOROUGHLY aware of the system you are working on.
For experienced developers, they can definitely pick the pace off at any point in time and start implementing their test cases, but for anyone who has not written a lot of test cases before, or at the start of their journey, this would be a hassle! not knowing what exactly that needs to be tested, or even not knowing how or where to start!
This is the basis of the approach I’m following in most of the given case scenarios, where basically we will build the end-system we would want to thoroughly test from scratch!
After having a brief on best practices in code/system modeling, and implementing these systems manually, we will dive deep into testing, where
We will mainly use the unittest framework in Python, which is a built-in easy to use module to get started as quickly as possible.
We will start implementing the mini-project in a Procedural manner (using the most basic modularization approach; functions).
We will then how to design and implement Unit Tests for our procedural code, by setting up our terms of agreement on what exactly should be defined as a “Unit”, as well as configuring of new project hierarchy (tree of folders).
We will have a walkthrough into one of the most common approaches used for testing; Test Driven Development, or TDD for short.
We will then have a Paradigm shift, where we travel to the OOP realm. I’m assuming you have a fair background in OOP, a brief recap will be given. (watch the promotional/intro video)
We will write Unit Tests for Object Oriented (classes) that we have created, and an update to our “unit” definition will take place.
We will see how useful your knowledge of the Command Line Interface (CLI) can be, by using your terminal session to inspect and debug your unit tests in real-time using the Python Interactive Debugger.
We will have real data, and we will learn how to sample them and/or fake them when needed
We will design and implement interrelated modules, we will also design and implement the relationships between them. And will know that by doing so, another different added layer/type of testing needs to be performed, which is Integration Testing, to make sure that integrated components, work as intended.
We will see a lot of coupled dependencies, which will lead us to isolate them completely using “Mocking” to perform our unit tests.
We will learn how to deal with intermediary or pass-through code, as it sometimes becomes unclear to whether you should test them or not.
We will learn how to generate test coverage reports (in HTML) and how to run multiple (unit and integration) tests simultaneously.
Finally, we will have an intensive walkthrough on files handlers and operations (such read, write, etc..) as well as the common stdout and stdout functions (such as print, input) and how to exactly test them for full coverage.
Who this course is for
Python developers who have some background in Python and want to dive in the software testing world.
CS/CE students in their first or second year who just got to read about software testing and TDD.
原创文章,作者:steven,如若转载,请注明出处:https://rr3d.cn/35884.html