Home Database Mysql Tutorial 查询分析器中开发代码测试检查_MySQL

查询分析器中开发代码测试检查_MySQL

Jun 01, 2016 pm 01:56 PM
develop Inquire test

如果您像我一样,则可能已经花费了很多时间在查询分析器中开发代码。在您对代码感到满意之后,可以立即对开发服务器上的测试数据库运行一个或两个专设 测试。如果看起来没有什么问题,您便可以将代码投入生产。如果这是一段关键代码,或者该代码较为复杂,则您可能会执行更多的检查,以避免后验剖析。甚至在这种情况下,您也可能屏息以待。www.chinai tp 采集 ow er.comd1nHRZf 

这就是我在大部分职业生涯中所采用的编码方式。哦,有时我会存储测试查询以供将来使用,这通常是因为总裁/CEO/CIO/部门经理习惯于大约每周就改变一下他或她的要求。但是,除此以外,我不会再做什么。我通常在查询分析器或它的 Oracle/Access/FoxPro 等效工具外部用专设 查询进行测试。更高强度的测试需要使用查询分析器调试器。在绝望的情形下,需要使用 PRINT 语句。www.chinai tp 采集 ow er.comd1nHRZf

目前存在 一种更好的方式。www.chinai tp 采集 ow er.comd1nHRZf

超越专设 测试www.chinai tp 采集 ow er.comd1nHRZf

当我的 SIL 部门采用极限编程 (XP) 时,我们还采用了该方法论的单元测试部分,而它们两者都使我成为更出色的开发人员。但是,即使您不在 XP 环境中工作,您仍然可以从 XP 风格的单元测试中获益。 www.chinai tp 采集 ow er.comd1nHRZf

单元测试不同于接受测试。单元测试用于测试较小的代码块(例如,存储过程),而接受测试更多地涉及到用户是否可以接受 UI。以下是我发现的单元测试的五个优点:www.chinai tp 采集 ow er.comd1nHRZf

? 它们能够找出应该承担责任的当事人。您是否收到过电子邮件,告诉您应该修复程序错误,而这实际上是其他某个人所作更改的副作用?好,如果您具有一些零散的测试查询,请将它们包装到可以定期运行(或许是在晚上)的存储过程中。请确保在单元测试失败时能够生成电子邮件。 www.chinai tp 采集 ow er.comd1nHRZf
 
? ;生成库不需要花费很长时间。每个存储过程和每个存储函数都应当具有为它编写的测试,而触发器也应该如此。如果这听起来有些苛刻,那么请想一想,能够在问题到达生产服务器之前捕捉到它,从而拯救您自己,将会是一种多么好的感觉。如果您具有大量旧式代码,那么为每个单元编写测试可能需要多年的工作,并且您也不能仅仅为了编写测试而停止新的开发工作。但是,您可以为每段新代码编写测试,也可以为您修改的每个过程编写测试。用不了多长时间,您就会为关键的旧式代码和新代码编写众多的测试。 www.chinai tp 采集 ow er.comd1nHRZf
 
? 轻松创建准确的代码文档。每个过程或函数都应当用不同的参数组合调用。这不仅能够确保代码按预期方式工作,而且还提供了有关您的工作的最新而准确的文档。另外一个编码员只需查看您的测试,就可以了解对您的过程进行调用的示例。谁知道呢?某一天,这另一个编码员可能就是您自己。 www.chinai tp 采集 ow er.comd1nHRZf
 
? 它们迫使您预先进行一点儿思考和计划。您应当在编写实际的过程或函数之前编写自己的单元测试。“什么?”您说,“我抗议!我们如何为尚未进行编码的东西编写测试?” www.chinai tp 采集 ow er.comd1nHRZf
 
? 有一个很老的笑话,它讲的是:有一个经理说:“我将弄清楚他们需要什么。其余的人开始编码。”那么,编码员在知道他们需要编写什么之前是无法开始工作的,不是吗?当您首先编写测试时,您将被迫考虑在开始编写该过程之前,您希望该过程完成什么工作。 www.chinai tp 采集 ow er.comd1nHRZf
 
? 它们确实可以节省您的时间。开发人员经常抱怨,编写测试需要花费比编写实际过程更多的时间。有时的确如此。但是请考虑以下情况:我最近接受了一项任务,即,修改我曾经遇到过的最难的存储过程之一。它是旧式代码,但是我仍然首先编写了测试。它花费了我几天的时间才完成,部分原因在于对该过程所施加的要求。实践证明,出于我刚才列出的所有原因,该测试非常重要,并且当我必须重新编写该过程以改善性能时,它变得弥足珍贵。 www.chinai tp 采集 ow er.comd1nHRZf
 
? 单元测试显示重新编写的过程中存在大量错误,而我能够很快地找到每个错误的根源,所花费的时间只占不使用单元测试时的几分之一。然后,当我认为已经完成该任务时,模糊测试失败了。主循环中的变量之一存在缺陷。如果代码以这种状态发布到生产环境中,那么这将是一个难以捕获的程序错误。最终,我以比采用其他方式更快的速度完成了这项任务。 www.chinai tp 采集 ow er.comd1nHRZf
 

如何编写 T-SQL 单元测试www.chinai tp 采集 ow er.comd1nHRZf

在我告诉您有关 T-SQL 测试框架的内容之前,首先需要提醒您注意两个非常基本的原则:www.chinai tp 采集 ow er.comd1nHRZf

? 第一,您需要一个具有良好测试数据的数据库。我用“良好数据”表示来自现实世界的真实数据。无论您是一个多么优秀的程序员,都无法充分地为应用程序仿造数据。即使要替换的旧式系统由纸张组成,也要找一位数据录入员来在某些表中输入数据。完成获得真实数据所需的工作。[尽管如此,仍然存在测试数据生成器。请参见本期中我的提示“生成测试数据”— 编者]www.chinai tp 采集 ow er.comd1nHRZf
 
? 第二,不应当针对生产数据库进行开发。您应当具有一个开发或测试数据库,以便满足您自己的需要。过去,当我在 Oracle 进行开发时,我曾经花费了一周的时间将开发数据库放在一个陈旧的服务器上。SQL Server 开发人员没有这样的借口。 www.chinai tp 采集 ow er.comd1nHRZf
 

在为开发数据库配备良好的数据以后,您需要某种框架以便运行测试。您可以编写自己的框架,但是为什么要这么做呢?已经有一个可用的框架了。www.chinai tp 采集 ow er.comd1nHRZf

TSQLUnit 简介www.chinai tp 采集 ow er.comd1nHRZf

TSQLUnit 是 T-SQL 的一个开放源码单元测试框架,它由 Henrik Ekelund 编写,并且可以从 http://sourceforge.net/projects/tsqlunit 获得。以下是一个有关我如何使用它的示例。www.chinai tp 采集 ow er.comd1nHRZf

我的 TSQLUnit 测试采用了类似的三部分模式:1) 单元测试设置,2) 执行目标过程,和 3) 检查结果。www.chinai tp 采集 ow er.comd1nHRZf

在单元测试设置过程中,我经常进行检查,以确保没有人趁我不注意时破坏了我的数据:www.chinai tp 采集 ow er.comd1nHRZf

DECLARE @nId INT, @nNewId INT a?”- @nNewId is for later

 

SELECT @nId = [ID] FROM MyTable

 

WHERE MyField = 'whatever'

 

IF @nId IS NULL  -- or @@ROWCOUNT = 0

 

EXEC tsu_failure 'The data has changed.

 

'whatever' couldn't be found'

 

IF 块用于检查预期的记录。如果找不到该记录,则测试会失败,并且会生成错误信息。测试框架移动至下一个单元测试。您不需要在失败消息字符串中使用该单元测试的名称,因为当测试失败时,TSQLUnit 将为您命名它。www.chinai tp 采集 ow er.comd1nHRZf

现在,我调用将要编写的存储过程:www.chinai tp 采集 ow er.comd1nHRZf

EXEC CreateMyTableNewRec @nId, @nNewId OUTPUT

 

正如您看到的那样,我已经确定了需要来自这一新过程的输出参数。在检查结果的过程中,我确保输出参数确实填充了某些内容:www.chinai tp 采集 ow er.comd1nHRZf

IF @nNewId IS NULL

 

EXEC tsu_failure

 

'A new record was not created for table MyTable.'

 

我可以进一步检查该值,以查看新记录是否是按照我希望的方式创建的。www.chinai tp 采集 ow er.comd1nHRZf

每个 TSQLUnit 测试本身都是一个存储过程。清单 1 显示了在将上述所有代码段放在一起时所具有的样子:www.chinai tp 采集 ow er.comd1nHRZf

清单 1. T-SQL 的完整单元测试。www.chinai tp 采集 ow er.comd1nHRZf

CREATE PROCEDURE ut_MyTable_NewRec

 

AS

 

--== Setup ==--

 

DECLARE @nID INT, @nNewId INT

 

SELECT @nId = ID FROM MyTable

 

WHERE MyField = 'whatever'

 

IF @nId IS NULL  -- or @@ROWCOUNT = 0

 

EXEC tsu_failure 'The data has changed.

 

'Whatever' couldn't be found'

 

--== Execute ==--

 

EXEC CreateMyTableNewRec @nId, @nNewId OUTPUT

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What do you think of furmark? - How is furmark considered qualified? What do you think of furmark? - How is furmark considered qualified? Mar 19, 2024 am 09:25 AM

What do you think of furmark? 1. Set the "Run Mode" and "Display Mode" in the main interface, and also adjust the "Test Mode" and click the "Start" button. 2. After waiting for a while, you will see the test results, including various parameters of the graphics card. How is furmark qualified? 1. Use a furmark baking machine and check the results for about half an hour. It basically hovers around 85 degrees, with a peak value of 87 degrees and room temperature of 19 degrees. Large chassis, 5 chassis fan ports, two on the front, two on the top, and one on the rear, but only one fan is installed. All accessories are not overclocked. 2. Under normal circumstances, the normal temperature of the graphics card should be between "30-85℃". 3. Even in summer when the ambient temperature is too high, the normal temperature is "50-85℃

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

How to check your academic qualifications on Xuexin.com How to check your academic qualifications on Xuexin.com Mar 28, 2024 pm 04:31 PM

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

12306 How to check historical ticket purchase records How to check historical ticket purchase records 12306 How to check historical ticket purchase records How to check historical ticket purchase records Mar 28, 2024 pm 03:11 PM

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Apr 22, 2024 pm 12:50 PM

The "Inaction Test" of the new fantasy fairy MMORPG "Zhu Xian 2" will be launched on April 23. What kind of new fairy adventure story will happen in Zhu Xian Continent thousands of years after the original work? The Six Realm Immortal World, a full-time immortal academy, a free immortal life, and all kinds of fun in the immortal world are waiting for the immortal friends to explore in person! The "Wuwei Test" pre-download is now open. Fairy friends can go to the official website to download. You cannot log in to the game server before the server is launched. The activation code can be used after the pre-download and installation is completed. "Zhu Xian 2" "Inaction Test" opening hours: April 23 10:00 - May 6 23:59 The new fairy adventure chapter of the orthodox sequel to Zhu Xian "Zhu Xian 2" is based on the "Zhu Xian" novel as a blueprint. Based on the world view of the original work, the game background is set

What are the differences between function testing and coverage in different languages? What are the differences between function testing and coverage in different languages? Apr 27, 2024 am 11:30 AM

Functional testing verifies function functionality through black-box and white-box testing, while code coverage measures the portion of code covered by test cases. Different languages ​​(such as Python and Java) have different testing frameworks, coverage tools and features. Practical cases show how to use Python's Unittest and Coverage and Java's JUnit and JaCoCo for function testing and coverage evaluation.

See all articles