如何使用 ADAM 运行单元测试?
我正在编写一个使用 Active Directory 来验证用户的网站。 我无权访问可以以任何方式编辑的 Active Directory 实例。
我听说有些人正在使用 Active Directory 应用程序模式 (ADAM) 创建用于单元和集成测试的 AD 数据。
还有其他人这样做过吗? 有什么好的网站/博客可以告诉您如何做到这一点吗? 存在哪些问题? 这是个好主意吗?
I writing a web site that uses Active Directory to validate users. I don't have access to an Active Directory instance that I can edit in any way.
I've heard that some people are using Active Directory Application Mode (ADAM) to create AD data to be used in Unit and Integration Testing.
Has anyone else done this? Are the any good site/blog that tells how to do this? What are the issues? Is this even a good idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这不是一个好主意,就像在单元测试中读取文件或访问数据库一样不是一个好主意。 您的测试将依赖于外部软件的状态。 或者你会有很多设置和拆卸代码。 如果您以这种方式编写测试,您可能会花费大量额外的时间来维护测试代码。 设置和维护构建服务器也将变得更加困难,并且为新程序员设置开发环境将花费更多时间。
在这种情况下,解决方法是围绕基础架构设置一个适配器类以调用 AD,并使用 rhino-mocks 或其他模拟框架之类的东西在测试中设置模拟活动目录。 如果您不熟悉嘲笑,这听起来像是很多工作。 但实际上,每次测试通常只需几行代码。
I don't think this is a good idea just like reading files or accessing the database in unit tests isn't a good idea. Your tests will become dependent on the state of an external piece of software. Or you will have a lot of setup and teardown code. If you write tests this way you can expect you'll spend a lot of extra time maintaining your test-code. Setting up and maintaining a build server will become harder too and setting up the development environment for new programmers will take more time.
The way to go in cases like this is to set up an adapter class around the infrastructure for calling into AD and to use something like rhino-mocks or another mocking framework to setup a mock-active-directory in your tests. If you're not familiar with mocking it sounds like a lot of work. But in practice it's usually only a couple of lines of code per test.