Get help with testing, discuss unit testing strategies etc.


Post by jflowers45 »

I wanted to share an approach I'm trying out for modularity in Siesta. I've only created the proof of concept so far and I haven't hit any snags. I don't have any specific technical question at the moment, but I'm curious if this sounds like a decent path to follow.

The primary mechanism in Siesta for code sharing seems to be inheritance. So, initially, I had all my tests inherit from a gigantic base class. This file got too big and unmanageable pretty quickly and mixes the code from several different application modules that we have into a single file.

We have roughly 10 modules, but for the sake of this discussion, let's talk about 3 and call the modules "Inventory", "Staffing", and "Contracts"

I could subclass the base class for each application module - resulting in an Inventory subclass, a Staffing subclass, and a Contracts subclass. The problem is that we have end to end tests that need to hit many different modules. I want to call logic for many different modules from a single test, and multiple inheritance isn't supported (probably not desirable either!).

After browsing the forum I stumbled upon a mention of Joose Roles and they seem to fit the bill. The solution I'm pursuing, and I've successfully created a proof of concept, is to:

1) Keep shared logic in BaseTestClass.js

2) Separate the the logic for each application module into unique Joose Roles. So, I've got role_inventory.js,
role_staffing.js
role_contracts.js

3) Create a test class called endToEndTest.js, which subclasses the main base class and consumes every role. This ends up looking something like
Class('e2eTest', {
   
    isa: baseTestClass,
    does: [role_inventory,role_staffing, role_contracts],

    methods: {
    }
})
At that point, any test that I write can be an instance of an e2eTest and has access to all of the shared code from the baseTestClass as well as the module code which was broken into individual files using the Joose roles mechanism.

Does this make sense as one approach?

Thanks!

-Joe

Post by nickolay »

Yes, perfectly make sense. You can also create several test classes, each with only specific set of roles included. And roles can include other roles :)

Post by jflowers45 »

Great, thanks Nikolay. The Joose is loose!!

Post Reply