Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xtreme-steve-elliott/4489ee022ec8982ee9febefab46ba675 to your computer and use it in GitHub Desktop.
Save xtreme-steve-elliott/4489ee022ec8982ee9febefab46ba675 to your computer and use it in GitHub Desktop.
IntelliJ Live Templates for generating: - TypeScript describe block with basic test, TestBed and fixture.detectChanges() - JUnit 5 test class w/ display name - JUnit 5 nested class w/ display name, - JUnit 5 test w/ display name. Place it in the `/templates` directory of your IntelliJ and restart.
<templateSet group="Steve's Custom Live Templates">
<template name="cdescr" value="import {async, ComponentFixture, TestBed} from '@angular/core/testing';&#10;import {NoopAnimationsModule} from '@angular/platform-browser/animations';&#10;&#10;describe($CLASS_NAME$.name, () =&gt; {&#10; let component: $CLASS_NAME$;&#10; let fixture: ComponentFixture&lt;$CLASS_NAME$&gt;;&#10;&#10; beforeEach(async(() =&gt; {&#10; TestBed.configureTestingModule({&#10; declarations: [&#10; $CLASS_NAME$&#10; ],&#10; providers: [],&#10; imports: [&#10; NoopAnimationsModule&#10; ]&#10; }).compileComponents();&#10; }));&#10;&#10; beforeEach(() =&gt; {&#10; fixture = TestBed.createComponent($CLASS_NAME$);&#10; component = fixture.componentInstance;&#10; fixture.detectChanges();&#10; });&#10;&#10; it('should create', () =&gt; {&#10; expect(component).toBeTruthy();&#10; });&#10;});&#10;" description="Inserts describe() block for a class" toReformat="true" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
<option name="TypeScript" value="true" />
</context>
</template>
<template name="j5tc" value="import org.junit.jupiter.api.DisplayName;&#10;import org.junit.jupiter.api.Nested;&#10;import org.junit.jupiter.api.Test;&#10;import org.junit.jupiter.api.extension.ExtendWith;&#10;import org.springframework.test.context.junit.jupiter.SpringExtension;&#10;&#10;@ExtendWith(SpringExtension.class)&#10;@DisplayName(&quot;$DISPLAY_NAME$&quot;)&#10;class $CLASS_NAME$ {&#10; $END$&#10;}" description="Inserts JUnit 5 Spring extenstion test class with display name" toReformat="false" toShortenFQNames="true">
<variable name="DISPLAY_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="CLASS_NAME" expression="capitalize(camelCase(DISPLAY_NAME))" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="tdn" value="@Test&#10;@DisplayName(&quot;$DISPLAY_NAME$&quot;)&#10;void $METHOD_NAME$() {&#10; $END$&#10;}" description="Inserts JUnit 5 Test with DisplayName" toReformat="false" toShortenFQNames="true">
<variable name="DISPLAY_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD_NAME" expression="camelCase(DISPLAY_NAME)" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="ndn" value="@Nested&#10;@DisplayName(&quot;$DISPLAY_NAME$&quot;)&#10;class $CLASS_NAME$ {&#10; $END$&#10;}" description="Inserts Nested JUnit 5 class with Display Name" toReformat="false" toShortenFQNames="true">
<variable name="DISPLAY_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="CLASS_NAME" expression="capitalize(camelCase(DISPLAY_NAME))" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
</templateSet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment