SpongePowered/LaunchWrapperTestSuite

Name: LaunchWrapperTestSuite

Owner: SpongePowered

Description: A LaunchWrapper JUnit Test Suite

Created: 2016-10-03 06:24:27.0

Updated: 2018-01-28 00:56:04.0

Pushed: 2017-04-10 19:39:44.0

Homepage: null

Size: 89

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

LaunchWrapperTestSuite

LaunchWrapperTestSuite makes it possible to run JUnit tests that require transformed classes. It provides a custom test runner that will load the test class in a separate LaunchClassLoader that applies previously configured transformers.

Setup

LaunchWrapperTestSuite can be used with any build system. The following examples will use Gradle.

  1. Add test dependency on LaunchWrapperTestSuite:

    ndencies {
    testCompile 'org.spongepowered:lwts:1.0.0'
    
    
  2. Implement a test tweak class that configures the transformers. LaunchWrapperTestSuite comes with AbstractTestTweaker which provides some utility methods and sets up the class loader to work with JUnit.

    age com.example.test.launch;
    
    rt net.minecraft.launchwrapper.LaunchClassLoader;
    rt org.spongepowered.lwts.AbstractTestTweaker;
    
    ic class MyTestTweaker extends AbstractTestTweaker {
    
    @Override
    public void injectIntoClassLoader(LaunchClassLoader loader) {
        // Important so we can configure some settings for JUnit
        super.injectIntoClassLoader(loader);
    
        // Configure your transformers here (a few examples below)
    
        // Access transformer
        registerAccessTransformer("META-INF/test_at.cfg");
    
        // Mixin environment
        MixinBootstrap.init();
        Mixins.addConfiguration("mixins.test.json");
        // Set Mixin side, otherwise you get a warning when running the tests
        MixinEnvironment.getDefaultEnvironment().setSide(SERVER);
    
        // Custom transformer
        loader.registerTransformer("com.example.test.launch.transformer.MyCustomTransformer");
    }
    
    
    
  3. Set a system property lwts.tweaker with the full qualified class name of your tweaker:

     {
    systemProperty 'lwts.tweaker', 'com.example.test.launch.MyTestTweaker'
    
    // Run tests in a temporary directory
    workingDir = {test.temporaryDir}
    
    
Usage

To make a test class use the custom test runner, all you need to do is add a annotation to it:

With(LaunchWrapperTestRunner.class)
ic class MyTest {

@Test
public void testSomething() {
    // ...
}


When you run your tests using gradle test it should load the test class in the custom classloader and apply the configured transformers.

Parameterized test

If you are using a parameterized test you need to change the test runner to LaunchWrapperParameterized:

With(LaunchWrapperParameterized.class)
ic class MyParameterizedTest {

@Parameterized.Parameters
public static Collection<Object[]> getParameters() {
    // ...
}



This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.