Use the Groovy IDE plugin

xiaoxiao2021-03-06  59

1. Configure Groovy IDE

l Statically install the Groovy IDE plugin by "Installing the Groovy IDE Plugin" in Eclipse3

l Window> Customize Perspective> Shortcuts> New

l Select the goovy item, including the New Groovy Class and New Groovy Unit Test

2. Create a Groovy class

l File> New> Project> Java Project

l Enter engineering name, such as TestGroovy

l Click the Finish button to complete the project creation

l File> New> New Groovy Class

l Enter the Groovy class name, such as Hellogroovy

l Click the Finish button, system prompt: Add Runtime Groovy Support and Auto Build To Project?

l Click Yes to add Groovy support: Groovy and ASM class libraries have been added to the build path (running the Groovy class)

l Groovy class With Groovy to extension, providing a code framework similar to the MAIN method in Java, exemplifying "Hello Groovy!"

Class Hellogroovy {

Static void main (args) {

PRINTLN "Hello Groovy!"

}

}

l You can see the code of the Groovy class is comparable than Java.

l Note: Since the Groovy IDE plugin is still in the development phase, the editing function is still very weak (not very easy)

3. Run the Groovy program

l Run> run

l Select Groovy in the left list, click the New button below.

l Groovy Main tab:

Ø Project: TestGroovy

Ø main class: (selection) Hellogroovy

l Click the RUN button, you will see the run results in the Console view.

4. Groovy unit test

l File> New> New Groovy Unit Test

l Enter the name, such as Groovytest

l Click the Finish button to generate a basic framework

Import groovy.util.groovytestcase

Ø Class Groovytest Extends Groovytestcase {

Void testsomething () {

askERT 1 == 1

}

}

l Groovy's unit test class must expand the GroovyTestCase class, just add a simple Assert statement in the example

l In addition to using Juint's assertion statement, GroovyTestCase adds some additional assertion statements:

Ø AssertArrayequals (Object [] expected, object [] value)

Ø AssertLength (Int Length, char [] array)

Ø AssertLength (int length) Ø assertlength (int length, object [] array)

Ø assertcontains (char expected, char [] array)

Ø assertcontains (int expected, int [] array)

Ø AssertToString (Object Value, String Expected)

Ø AssertInspect (Object value, String Expected)

Ø AssertScript (Final String Script) // Asnee, there is no abnormality

Ø ShouldFail (Closure Code) // Ask the closure without throwing anomaly

Ø Should Fail (Class Clazz, Closure Code) // Only, just targeting class

In addition, in the Groovy script, the assertion statement can be used directly, as described below:

X = [1, 2, 3]

askERT X.SIZE () == 3

5, run the Groovy test case

l Run> run

l Select Juint in the left list, click the New button below.

l Test tab, select Run A Single Test:

Ø Project: TestGroovy

Ø TEST CLASS: (Select) Groovy.util.groovytestsuite (this is a JUnit Testsuite, used to compile and run the Groovy test case)

l Add: -dtest = src / groovytest.groovy (providing TEST system properties to specify the Groovy test case to run)

l Click the RUN button, you will see the test results in the JUInt view (you need to open the Juint view yourself)

转载请注明原文地址:https://www.9cbs.com/read-117971.html

New Post(0)