Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Testing Scaffolding #29

Open
dmadisetti opened this issue Mar 26, 2023 · 1 comment
Open

[Feature Request] Testing Scaffolding #29

dmadisetti opened this issue Mar 26, 2023 · 1 comment

Comments

@dmadisetti
Copy link
Contributor

I think unit tests are great. Manually testing these endpoints, but it would be nice to ensure we have reproduciblilty. Not sure how this works with the stripped versions of KSP? I also think there likely has to be a bit more in place to actively do proper testing

@djungelorm
Copy link
Member

What we do for krpc1, is write tests for the various endpoints as python scripts, then occasionally (manually) run them with a local copy of the game running. I try and run them when a new version of the game comes out, before a new release of the mod or if some large change is made. (The krpc1 tests have fallen into disrepair recently though and need to be updated...)

The tests use a python package called krpctest and a service DLL called TestingTools that give you functionality for doing things like loading new save games, loading craft files included with the test, and teleporting vessels into defined orbits. This makes setting up the game ready to run the tests more automatic. You just manually start the game, then run the test script, and it sets up the various vessels/orbits/etc ready for the test to run.

The tests for the krpc1 SpaceCenter service are here: https://github.com/krpc/krpc/tree/main/service/SpaceCenter/test

For example, one of the orbit tests looks like this:

class TestOrbit(krpctest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.new_save()
        cls.space_center = cls.connect().space_center

    ...

    def test_vessel_orbiting_kerbin(self):
        self.set_circular_orbit('Kerbin', 100000)
        vessel = self.space_center.active_vessel
        orbit = vessel.orbit
        self.assertEqual('Kerbin', orbit.body.name)
        self.assertAlmostEqual(100000 + 600000, orbit.apoapsis, delta=50)
        self.assertAlmostEqual(100000 + 600000, orbit.periapsis, delta=50)
        self.assertAlmostEqual(100000, orbit.apoapsis_altitude, delta=50)
        self.assertAlmostEqual(100000, orbit.periapsis_altitude, delta=50)
        self.assertAlmostEqual(100000 + 600000,
                               orbit.semi_major_axis, delta=50)
        self.assertAlmostEqual(100000 + 600000,
                               orbit.semi_minor_axis, delta=50)
        self.assertAlmostEqual(700000, orbit.radius, delta=50)
        self.assertAlmostEqual(2246.1, orbit.speed, delta=1)
        self.check_radius_and_speed(vessel, orbit)
        # self.check_time_to_apoapsis_and_periapsis(vessel, orbit)
        self.assertIsNaN(orbit.time_to_soi_change)
        self.assertAlmostEqual(0, orbit.eccentricity, places=1)
        self.assertAlmostEqual(0, orbit.inclination, places=1)
        # self.assertAlmostEqual(0,
        #                        orbit.longitude_of_ascending_node, places=1)
        # self.assertAlmostEqual(0, orbit.argument_of_periapsis, places=1)
        # self.assertAlmostEqual(0, orbit.mean_anomaly_at_epoch, places=1)
        # self.assertAlmostEqual(0, orbit.epoch, places=1)
        # self.check_anomalies(vessel, orbit)
        self.assertIsNone(orbit.next_orbit)

To get this style of testing working for krpc2 we would need the following:

I can create a bunch of issue to get these various parts implemented.


I don't think getting these to run automatically with each PR using github actions is practical:

  • You would need to have the game running inside the action. This would come up against copyright issues (as we would need to make a full copy of the game available to gh actions!)
  • GH actions would somehow need its own logged in steam account (is that even possible? can you log in a headless manner?)
  • and it would also need to run on a vm with plenty of storage, a beefy graphics card and cpu (GH's free hosted runners don't get anywhere near the minimum spec requirements).

We could maybe host our own runner with the above requirements, but I'm not sure it's really worth the effort. The testing approach for krpc1 seemed to work well enough for this kind of testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants