Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Integration Tests for SFD scripts and maps

Share questions, scripts and tutorials related to the ScriptAPI in SFD.
Forum rules
By using the forum you agree to the following rules.
Post Reply
Posts: 52
Joined: Sun Jun 12, 2016 1:07 am
Title: Superfighter
SFD Account: Juansero29
SFD Alias: Juansero29
Started SFD: Pre-Alpha 1.0.5
Location: France
Age: 23

Integration Tests for SFD scripts and maps

Post by Juansero29 » Sun Mar 28, 2021 4:37 pm

Since some of you know, I'm actively supporting and developing features for the Hardcore server, which includes a multiple of maps all using the same base script. I have refactored a lot of the code running in this maps but my goal is to have a really reliable code, that can be tested and will behave as I expect it to behave, always.

For this, I would need to do some unit testing (testing classes and components of the script by themselves) and integration testing (testing the script along with the map and checking that the objects that are retrieved have the expected values or have certain behaviors I want them to have.

For Unit Testing, I can see already some tests with only the classes the script uses, but there's little thing to do a part from verifying a couple of methods and properties. I think for the Hardcore script this is not as important.

For Integration testing, however, there's a lot to be done. Here is a list of things that I would like to check, as en example of assertions:
  • That some object has effectively appeared under certain conditions
  • That a player has effectively gone to a state I would like him to have (dead, alive, stunned, etc...)
  • That some bullets have actually spawned at a certain vector and that they are going in the direction I want them to go
  • That a game has effectively started, or ended
  • That some points are actually attributed to players when they make a kill
The list could go on and on, but I don't see any way to do this in a classic way. In C# I would have used Mocks and Assertions to do this in a normal desktop/web/mobile application, and probably some UI test framework. However, since the script concerns SFD's Engine, XNA's Engine and actually things happening inside the game world, I don't have any idea on how to test this effectively.

I tried doing a mock of the "IGame" class using the Moq framework like this:

Code: Select all

            GameMock = new Mock<IGame>();
            GameMock.Setup(m => m.GetSingleObjectByCustomId("IdOfALedgeGrabIObject")).Returns(() => new [what type to use here??] ()());
The thing is, most of the objects returned by 'GetSingleObjectByCustomId' or 'GetObjectsByCustomId' are actually proxies and can't instantiated since their type is always abstract, and we don't have access to their concrete types.

Also methods like 'Game.CreateObject()', 'Game.PlaySound()' or 'Game.SpawnProjectile()' can't actually be mocked since they directly impact the world map, and from code I don't see how we could assert that they have done their job.

So, that is my question, is it possible to automate integration testing for the scripts in code? Or is the only way to test code to actually run the map and see how stuff behaves, meaning there's no automation viable to be done?
0 x

Code: Select all

boom() {
  echo "BOOM!";			
Setting the world free since 1998

Post Reply