Skip to content

Commit bd3f68f

Browse files
author
Roberto De Ioris
authored
Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md
1 parent a45ed61 commit bd3f68f

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,63 @@ class PlotComponent:
125125
### Playing it
126126

127127
### Writing a simple unit test
128+
129+
Sorry, i will never stop telling you how important unit tests are, so, even if we have deloped a really simple script, we will write a unit test too :)
130+
131+
We need to test that when a 'ComponentOverlap' event is triggered on a cube, the right counter is incremented:
132+
133+
```python
134+
import unittest
135+
import unreal_engine as ue
136+
from unreal_engine.classes import Blueprint
137+
138+
class TestPlotterPlatform(unittest.TestCase):
139+
140+
def setUp(self):
141+
ue.allow_actor_script_execution_in_editor(True)
142+
ue.begin_transaction('test')
143+
self.world = ue.get_editor_world()
144+
self.blueprint = ue.load_object(Blueprint, '/Game/PlotterPlatforms.PlotterPlatforms')
145+
146+
def tearDown(self):
147+
ue.end_transaction()
148+
ue.editor_undo()
149+
ue.allow_actor_script_execution_in_editor(False)
150+
151+
def test_red_cube_overlap(self):
152+
actor = self.world.actor_spawn(self.blueprint.GeneratedClass)
153+
self.assertEqual(actor.RedCubeCounter, 0)
154+
actor.RedCube.broadcast('OnComponentBeginOverlap')
155+
self.assertEqual(actor.RedCubeCounter, 1)
156+
self.assertEqual(actor.GreenCubeCounter, 0)
157+
self.assertEqual(actor.BlueCubeCounter, 0)
158+
159+
def test_green_cube_overlap(self):
160+
actor = self.world.actor_spawn(self.blueprint.GeneratedClass)
161+
self.assertEqual(actor.GreenCubeCounter, 0)
162+
actor.GreenCube.broadcast('OnComponentBeginOverlap')
163+
self.assertEqual(actor.RedCubeCounter, 0)
164+
self.assertEqual(actor.GreenCubeCounter, 1)
165+
self.assertEqual(actor.BlueCubeCounter, 0)
166+
167+
def test_blue_cube_overlap(self):
168+
actor = self.world.actor_spawn(self.blueprint.GeneratedClass)
169+
self.assertEqual(actor.BlueCubeCounter, 0)
170+
actor.BlueCube.broadcast('OnComponentBeginOverlap')
171+
self.assertEqual(actor.RedCubeCounter, 0)
172+
self.assertEqual(actor.GreenCubeCounter, 0)
173+
self.assertEqual(actor.BlueCubeCounter, 1)
174+
175+
if __name__ == '__main__':
176+
unittest.main(exit=False)
177+
```
178+
179+
You can run the unit test with:
180+
181+
```python
182+
ue.sandbox_exec('test_plotter_platforms.py')
183+
```
184+
185+
the 'sanbox' execution, ensures a clean python subinterpeter is initialized, instead of clobberign the main one.
186+
187+
Check how the test setUp and tearDown methods, ensure your world is cleaned up at the end (using the transaction api of unreal engine: https://github.com/20tab/UnrealEnginePython/blob/master/docs/Transactions_API.md)

0 commit comments

Comments
 (0)