在练习TDD(单元测试)时学习OpenGL

编程入门 行业动态 更新时间:2024-10-15 12:32:05
本文介绍了在练习TDD(单元测试)时学习OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我开始了一个新的游戏项目,并决定学习和使用OpenGL(项目是在Windows和Linux上同时开发的)。同时,我也非常感兴趣的测试驱动开发,我试图尽我所能在写任何实际代码之前编写我的单元测试来引导设计。

然而,我认为我的缺乏知识可能会让我失望,我试图写一个墙,试图写我的单元测试的渲染部分的代码库。我希望有人可以给我一些有关如何继续的见解。

我知道我需要单元测试我与OpenGL的交互,而不是OpenGL本身。我可以看到这样做的唯一方法是通过截取OpenGL函数调用,或通过创建一个全新的类接口,从而允许我创建该类的模拟版本,从而使OpenGL远离我的代码的其余部分用于测试。 (更好的是将它们抽象为一组单独的命名空间中的非类函数,而不是虚拟类抽象,但我不知道我该如何嘲笑它。)

然而,由于我还在学习OpenGL,我只是对这个抽象应该是什么样子的一个想法。例如,我应该包装每个OpenGL调用,或者根据要完成的任务将它们分组到更高级的功能?薄包装器只会调用一个特定的OpenGL函数,所以我不需要预先测试它们,但是我可以结束大量的函数来包装。然后,再次,如果我走得太远,另一种方式,并将多个OpenGL调用集合在一起的任务,我觉得我会结束在我开始,有一大堆代码使用OpenGL本身需要在使用前测试。 / p>

中间地点在哪里?

解决方案

正确测试渲染是不值得的努力。但是,在设计应用程序时,您仍然可以使用TDD。

这是一篇有关TDD,游戏和OpenGL的精彩文章。

I have started a new game project, and have decided to learn and use OpenGL for it (project is being simultaneously developed on Windows and Linux). At the same time, I am also very interested in Test Driven Development, and am trying to put my best effort into writing my unit tests to lead design before any actual code.

However, I think my lack of knowledge might be tripping me up, and I keep hitting a wall in trying to write my unit tests for the "rendering" parts of the codebase. I'm hoping someone can give me some insight on how to continue.

I know that I need to unit test my interactions with OpenGL, and not OpenGL itself. The only way I can see to do this is to abstract OpenGL away from the rest of my code to some extent, either by intercepting OpenGL function calls, or by creating a whole new class interface, allowing me to create a mock version of that class for the tests. (Even better would be to abstract them to a set of non-class functions in a separate namespace rather than virtual class abstractions, but I don't see how I could mock that.)

However, as I'm still learning OpenGL, I only have a passing idea of what that abstraction should look like. For example, shall I wrap each OpenGL call, or group them into higher-level functions based on tasks to be accomplished? Thin wrappers would do little more than call a particular OpenGL function, so I wouldn't need to test them beforehand, but I could end up with a large number of functions to wrap. Then again, if I go too far the other way and group multiple OpenGL calls together by task, I feel like I'll end up where I started, having a large body of code using OpenGL that itself needs to be tested before use.

Where is the middle ground? How to I learn to use OpenGL while at the same time doing proper unit testing beforehand?

解决方案

Properly testing rendering is not worth the effort. However, you can still use TDD for everything else and while designing your application.

Here's a great article about TDD, games, and OpenGL.

更多推荐

在练习TDD(单元测试)时学习OpenGL

本文发布于:2023-11-30 02:10:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   TDD   OpenGL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!