TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to learn how to write great tests in Python?

1 点作者 ajushi大约 5 年前
I need help. I want to improve. I feel that I'm not writing the best unit tests. Can you guys recommend any books or articles where I can learn how especially in Python? I'm more concerned about strategies about knowing what tests to write and when is the best scenario to write them. I really want to be good at development and this area is what I think I'm lacking. I'd really appreciate your help. Thank you.

2 条评论

andrewmatte大约 5 年前
My best advice for you is to write modular functions that can be tested separately rather than integrated stuff that can&#x27;t be disentangled.<p>A unit test should test the functionality of a single chunk of code. What kind of stuff are you writing?<p>I write webservers most of the time. So what I do is, at the top level of the request, immediately pull data off of the request so that I can access to the data in native python types that are easy to mock for testing. Each layer of my webserver does only one thing which could be gluing the auth+services together, but is still easy to mock.
_ology大约 5 年前
You might have a look at the O&#x27;Reilly book from August 2, 2017: &quot;Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript&quot; 2nd Edition