Search code examples
javajunitjunit4xtextjunit5

Upgrading JUnit4 to JUnit5 in a xtext environment


I'm working on a complex project which uses xtext. My job is to upgrade the testing from JUnit4 to JUnit5. The problem is, for the JUnit tests there are 2 "InjectorProvider" classes generated by a *.mwe2 file and i cannot figure out how to upgrade the generation of these files to JUnit5.

The *.mwe2 file contains in its workflow section currently org.eclipse.xtext.generator.Generator which contains: fragment = junit.Junit4Fragment auto-inject {}.

Generator is deprecated and i don't understand how to migrate the complete Generator to the new/suggested XtextGenerator. At the same time i cannot find a replacement for the JUnit4 fragment.

The Workflow:

Workflow {
 bean = //...
 component = //...
 component = //...
 component = Generator {
    pathRtProject = runtimeProject
    pathUiProject = "${runtimeProject}.ui"
    pathTestProject = "${runtimeProject}.tests"
    projectNameRt = projectName
    projectNameUi = "${projectName}.ui"
    encoding = encoding
    language = auto-inject {        
        uri = grammarURI
    fileExtensions = fileExtensions
    fragment = //... many of these fragments
    fragment = junit.Junit4Fragment auto-inject {}
 }
}

I would appreciate any sort of hint or help, on how to migrate this to the new org.eclipse.xtext.xtext.generator.XtextGenerator or how to get the JUnit5 fragment functional or what topics i have to read into to get this done.

I'm sorry if this is too vague or proofs my incompetence, but i'm just an intern on his own, trying to get this fixed. Please keep it simple, i have limited experience.


Solution

  • Seems like my project is quite old and i am jumping several big releases from xtext. In case somebody lands here, i managed to get further by using the new XtextGenerator (code below) and restructuring the project. In particular the new Generator needs an .ide package. So i created a new projekt, used the wizard to create a JUnit 5 project and copied/renamed the needed directoys around. now i have to fix occuring Errors and sticht my project back together. Heres the newGenerator template:

    component = XtextGenerator {
        configuration = {
            project = model.project.StandardProjectConfig {
    
                baseName = "com.xxx.xxx.dsl.xxx"
                rootPath = ".."
                runtimeTest = {
                    enabled = true
                }
                eclipsePlugin = {
                    enabled = true
                }
                eclipsePluginTest = {
                    enabled = false
                }
                createEclipseMetaData = true
            }
            code = {
                encoding = "UTF-8"
                lineDelimiter = "\r\n"
                fileHeader = "/*\n * generated by Xtext \${version}\n */"
            }
        }
        language = StandardLanguage {
            name = "com.xxx.xxx.xxx.xxx.xxxDSL"
            fileExtensions = "xxx"
    
            serializer = {
                generateStub = true
            }
            validator = {
                // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
                // Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage
                generateDeprecationValidation = true
            }
            junitSupport = {
                junitVersion = "5"
            }
        }