GithubHelp home page GithubHelp logo

isabella232 / launchwrappertestsuite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spongepowered/launchwrappertestsuite

0.0 0.0 0.0 89 KB

A LaunchWrapper JUnit Test Suite

License: MIT License

Java 100.00%

launchwrappertestsuite's Introduction

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:

    dependencies {
        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.

    package com.example.test.launch;
    
    import net.minecraft.launchwrapper.LaunchClassLoader;
    import org.spongepowered.lwts.AbstractTestTweaker;
    
    public 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:

    test {
        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:

@RunWith(LaunchWrapperTestRunner.class)
public 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:

@RunWith(LaunchWrapperParameterized.class)
public class MyParameterizedTest {

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

}

launchwrappertestsuite's People

Contributors

stephan-gh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.