使用 NUnit 和 Console 进行单元测试
我一直在使用curses Sharp 库(pdcurses 的ac# 包装器),编写一些单元测试代码来获取api 的句柄及其工作原理,并且我提出了一个问题。
我可以使用以下代码从 DLL 中运行curses Sharp(以便 nUnit 可以测试它):
bool consoleAllocated = AllocConsole();
if (!consoleAllocated)
throw new Exception("Unable to allocate a new console.");
Curses.InitScr();
Stdscr.Add(4, 6, "This is a test title");
Curses.EndWin();
FreeConsole();
AllocConsole 和 FreeConsole 是从 kernel32 导入的 extern。
我想做的是能够将控制台输出从位置 4,6 读取到字符串,以便以编程方式检查我输入的字符串是否已正确输出。例如,为了使用 TDD 创建一个 Curses 风格的应用程序,能够进行这样的检查是非常重要的。
我已经查看了 Curses 和 Stdscr 对象(都是 Curses Sharp 对象)以及 Console 对象(来自 Windows 库),但还没有找到方法。有人有什么想法吗?
I've been playing around with the curses sharp library (a c# wrapper for pdcurses), writing some unit test code to get a handle on the api and how it works, and I've come up with a question.
I can run curses sharp from within a DLL (so that nUnit can test it), using the following code:
bool consoleAllocated = AllocConsole();
if (!consoleAllocated)
throw new Exception("Unable to allocate a new console.");
Curses.InitScr();
Stdscr.Add(4, 6, "This is a test title");
Curses.EndWin();
FreeConsole();
AllocConsole and FreeConsole are extern's imported from kernel32.
What I would like to do is be able to read the console output from position 4,6 to a string so as to programmatically check that the string I've entered has been output correctly. It would be pretty important to be able to do checks like this in order to create a curses-style app using TDD for instance.
I've looked over the Curses and Stdscr objects (both Curses Sharp objects), and the Console object (from the windows library) and haven't been able to find a way yet. Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法找到了答案,如果有人感兴趣,我已经包含了下面的代码。它很乱,因为我还没有清理它,但它应该作为如何做到这一点的示例。
感谢 pinvoke.net 提供的优秀签名合集。
I managed to find an answer, in case anyone was interested I've included the code below. It's messy, as I haven't cleaned it up yet, but it should serve as an example as to how to do this.
Thanks to pinvoke.net for their excellent signature collection.