junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
779 stars 112 forks source link

GWT unit testing #118

Closed DaanVanYperen closed 10 years ago

DaanVanYperen commented 10 years ago

Found something that might tickle your fancy!

Got a GWT unit testing module in the dev branch of odb-contrib working, with an example artemis test case. https://github.com/DaanVanYperen/artemis-odb-contrib/tree/develop/contrib-test-gwt

Tests are easy to write. Shouldn't need to boot the environment more than once. It'll probably beat having to monkey test GWT with Spaceship Warrior Redux. ;)

public class BasicArtemisGwtTest extends GWTTestCase {

    @Override
    public String getModuleName() {
        return "net.mostlyoriginal.ContribTest";
    }

    public void test_runartemis_processsimplesystem_noexceptions() throws Exception {
        World w = new World();
        w.setManager(new TagManager());

        CountingTestSystem s = new CountingTestSystem();
        w.setSystem(s);
        w.initialize();
        w.process();

        assertEquals(1, s.count);
    }
}

I'm up to speed so let me know if you want a draft module pushed for artemis.

DaanVanYperen commented 10 years ago

Also i'm severely paranoid it's not actually running the tests as javascript. ._o

Edit: it needs a bit more tweaking. XD Edit 2: Works fine now.. ;) Faster too.

junkdog commented 10 years ago

Heh, interesting - I wonder if the tests from artemis-odb can be re-used as-is (with or without some automatated rewriting). Will look into.

DaanVanYperen commented 10 years ago

I'm pretty sure you can. I know at leasat Surefire can run GWTTestCase as java, it's at top of the maven-gwt plugin page about testing. (I was actually running them under java for a bit by accident). Besides that libGDX has some multi platform test cases I believe, playn too.

Just going to use it to test things that always break, like annotations. Had my fill of GWT for now ;)

Edit: I had to use exclusion/inclusion rules so maven-gwt grabs the gwt tests, and surefire runs its own tests. the GWTTestCase uses the naming convention public void test_ to find tests, accidentally left some @Test annotations in there and it didn't break the GWT tests, so that might be all you need. ;)

junkdog commented 10 years ago

Ugh, looked into unit testing GWT... turns out they're still on JUnit 3. Not that so many things changed between 3 and 4, but it's 120 test cases to edit (actually less, since artemis-weaver doesn't count). Maybe some quick and dirty regexed sed-ing could be hooked into the gwt module, generating all modified test classes automatically each time it's run.

DaanVanYperen commented 10 years ago

What's still on JUnit3? Or do you mean they're still using the old package names?

Edit: wait you mean the GWT way to test is JUnit3 style?

junkdog commented 10 years ago

Yup, I guess it'll be a matter of issuing "organize imports" on the top level test folders in eclipse and then manually removing all annotations while ensuring that the methods are properly named.

DaanVanYperen commented 10 years ago

static import ALL THE THINGS! Wraap.

junkdog commented 10 years ago

Tomorrow is election day, so this probably won't be done before beginning of next week.

DaanVanYperen commented 10 years ago

If you are running low on time just having a single test will help a lot. It's typically the build process that fails.

Nb. If we tie into the future LibGDX reflection lib, is there any reason to use their GWT testing scaffolding as well? Might be worth it just to push this to 0.8 and wait for the GWT refactoring.

junkdog commented 10 years ago

I'll have to look into how they test their stuff - they have a knack for clever hacks.