BAEL-2780 | spock extensions
This commit is contained in:
parent
01ab66f84f
commit
6ce8073fde
|
@ -0,0 +1,402 @@
|
|||
loadLogFile([{
|
||||
"package": "mocks",
|
||||
"name": "ExampleSpockTest",
|
||||
"start": 1553898111660,
|
||||
"features": [
|
||||
{
|
||||
"name": "should calculate character occurrences in given string",
|
||||
"start": 1553898111662,
|
||||
"end": 1553898111699,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898111709,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "mocks",
|
||||
"name": "ItemServiceTest",
|
||||
"start": 1553898111714,
|
||||
"features": [
|
||||
{
|
||||
"name": "should spy on EventPublisher method call",
|
||||
"start": 1553898111714,
|
||||
"output": [
|
||||
"I've published: item-id\n"
|
||||
],
|
||||
"end": 1553898112250,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should return items",
|
||||
"start": 1553898112250,
|
||||
"end": 1553898112260,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should publish events about new non-empty saved offers",
|
||||
"start": 1553898112260,
|
||||
"end": 1553898112267,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should return different items for different ids lists",
|
||||
"start": 1553898112267,
|
||||
"end": 1553898112280,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should throw ExternalItemProviderException when ItemProvider fails",
|
||||
"start": 1553898112281,
|
||||
"end": 1553898112294,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should return different items on subsequent call",
|
||||
"start": 1553898112294,
|
||||
"narrative": "When method is called for the first time\nThen empty list is returned\nWhen method is called for the second time\nThen item with id=1 is returned\nWhen method is called for the thirdtime\nThen item with id=2 is returned",
|
||||
"end": 1553898112298,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should return items sorted by name",
|
||||
"start": 1553898112299,
|
||||
"end": 1553898112307,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898112310,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "FirstSpecification",
|
||||
"name": "FirstSpecification",
|
||||
"start": 1553898112314,
|
||||
"features": [
|
||||
{
|
||||
"name": "Should verify notify was called",
|
||||
"start": 1553898112314,
|
||||
"end": 1553898112324,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Should return true value for mock",
|
||||
"start": 1553898112325,
|
||||
"end": 1553898112344,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Should return default value for mock",
|
||||
"start": 1553898112344,
|
||||
"end": 1553898112347,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "numbers to the power of two",
|
||||
"start": 1553898112347,
|
||||
"end": 1553898112358,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Should get an index out of bounds when removing a non-existent item",
|
||||
"start": 1553898112358,
|
||||
"end": 1553898112364,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Should be able to remove from list",
|
||||
"start": 1553898112364,
|
||||
"end": 1553898112366,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "two plus two should equal four",
|
||||
"start": 1553898112366,
|
||||
"end": 1553898112368,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "one plus one should equal two",
|
||||
"start": 1553898112368,
|
||||
"end": 1553898112391,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898112394,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "IgnoreTest",
|
||||
"start": 1553898112395,
|
||||
"end": 1553898112395,
|
||||
"result": "skipped"
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "RetryTest",
|
||||
"start": 1553898112403,
|
||||
"end": 1553898112405,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "This title is easy to read for humans",
|
||||
"start": 1553898112407,
|
||||
"end": 1553898112408,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "SeeTest",
|
||||
"start": 1553898112409,
|
||||
"end": 1553898112411,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "StepwiseTest",
|
||||
"start": 1553898112422,
|
||||
"end": 1553898112423,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "NarrativeDescriptionTest",
|
||||
"start": 1553898112427,
|
||||
"narrative": "as a user\n i want to save favourite items \n and then get the list of them",
|
||||
"end": 1553898112433,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "SubjectTest",
|
||||
"start": 1553898112434,
|
||||
"end": 1553898112436,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "IgnoreRestTest",
|
||||
"start": 1553898112437,
|
||||
"end": 1553898112437,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "StackTraceTest",
|
||||
"start": 1553898112438,
|
||||
"features": [
|
||||
{
|
||||
"name": "stacktrace",
|
||||
"start": 1553898112438,
|
||||
"exceptions": [
|
||||
"java.lang.RuntimeException: blabla\n\tat extensions.StackTraceTest.stacktrace(StackTraceTest.groovy:10)\n"
|
||||
],
|
||||
"end": 1553898112455,
|
||||
"result": "failed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898112470,
|
||||
"result": "failed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "IgnoreIfTest",
|
||||
"start": 1553898112471,
|
||||
"end": 1553898112472,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "RequiresTest",
|
||||
"start": 1553898112473,
|
||||
"features": [
|
||||
{
|
||||
"name": "I will run only on Windows",
|
||||
"start": 1553898112474,
|
||||
"end": 1553898112474,
|
||||
"result": "skipped"
|
||||
}
|
||||
],
|
||||
"end": 1553898112476,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "IssueTest",
|
||||
"start": 1553898112477,
|
||||
"features": [
|
||||
{
|
||||
"name": "I'm using Spock configuration file",
|
||||
"start": 1553898112477,
|
||||
"tags": [
|
||||
{
|
||||
"name": "Bug LO-1000",
|
||||
"key": "issue",
|
||||
"value": "LO-1000",
|
||||
"url": "http:\/\/jira.org\/issues\/LO-1000"
|
||||
}
|
||||
],
|
||||
"end": 1553898112489,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898112490,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "TimeoutTest",
|
||||
"start": 1553898112491,
|
||||
"features": [
|
||||
{
|
||||
"name": "I will fail after 200 millis",
|
||||
"start": 1553898112491,
|
||||
"end": 1553898112514,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898112517,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
||||
loadLogFile([{
|
||||
"package": "extensions",
|
||||
"name": "RestoreSystemPropertiesTest",
|
||||
"start": 1553898112518,
|
||||
"features": [
|
||||
{
|
||||
"name": "all environment variables will be saved before execution and restored after tests",
|
||||
"start": 1553898112518,
|
||||
"end": 1553898112532,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"end": 1553898112539,
|
||||
"result": "passed",
|
||||
"attachments": [
|
||||
|
||||
]
|
||||
}])
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Title
|
||||
|
||||
|
||||
@Title("""This title is easy to read for humans""")
|
||||
class CustomTitleTest extends Specification {
|
||||
|
||||
}
|
||||
|
||||
@Narrative("""
|
||||
as a user
|
||||
i want to save favourite items
|
||||
and then get the list of them
|
||||
""")
|
||||
class NarrativeDescriptionTest extends Specification {
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.IgnoreIf
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class IgnoreIfTest extends Specification {
|
||||
|
||||
@IgnoreIf({System.getProperty("os.name").contains("windows")})
|
||||
def "I won't run on windows"() { }
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.IgnoreRest
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class IgnoreRestTest extends Specification {
|
||||
|
||||
def "I won't run"() { }
|
||||
|
||||
@IgnoreRest
|
||||
def 'I will run'() { }
|
||||
|
||||
def "I won't run too"() { }
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.Specification
|
||||
|
||||
@Ignore
|
||||
class IgnoreTest extends Specification {
|
||||
|
||||
@Ignore
|
||||
def "I won't be executed"() {
|
||||
expect:
|
||||
true
|
||||
}
|
||||
|
||||
def 'Example test'() {
|
||||
expect:
|
||||
true
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class IssueTest extends Specification {
|
||||
|
||||
|
||||
@Issue("http://jira.org/issues/LO-531")
|
||||
def 'single issue'() {
|
||||
}
|
||||
|
||||
@Issue(["http://jira.org/issues/LO-531", "http://jira.org/issues/LO-123"])
|
||||
def 'multiple issues'() {
|
||||
}
|
||||
|
||||
@Issue("LO-1000")
|
||||
def "I'm using Spock configuration file"() {
|
||||
expect:
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.PendingFeature
|
||||
|
||||
class PendingFeatureTest {
|
||||
|
||||
@PendingFeature
|
||||
def 'test for not implemented yet feature'() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Requires
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class RequiresTest extends Specification {
|
||||
|
||||
@Requires({ System.getProperty("os.name").contains("windows") })
|
||||
def "I will run only on Windows"() {
|
||||
expect:
|
||||
true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.util.environment.RestoreSystemProperties
|
||||
|
||||
|
||||
class RestoreSystemPropertiesTest extends Specification {
|
||||
|
||||
@RestoreSystemProperties
|
||||
def 'all environment variables will be saved before execution and restored after tests'() {
|
||||
given:
|
||||
System.setProperty('os.name', 'Mac OS')
|
||||
|
||||
expect:
|
||||
true
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Retry
|
||||
import spock.lang.Specification
|
||||
|
||||
@Retry
|
||||
class RetryTest extends Specification {
|
||||
|
||||
@Retry
|
||||
def 'I will retry three times'() { }
|
||||
|
||||
@Retry(exceptions = [RuntimeException])
|
||||
def 'I will retry only on RuntimeException'() { }
|
||||
|
||||
@Retry(condition = { failure.message.contains('error') })
|
||||
def 'I will retry with a specific message'() { }
|
||||
|
||||
@Retry(delay = 1000)
|
||||
def 'I will retry after 1000 millis'() { }
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.See
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class SeeTest extends Specification {
|
||||
|
||||
|
||||
@See("https://example.org")
|
||||
def 'Look at the reference'() {
|
||||
|
||||
}
|
||||
|
||||
@See(["https://example.org/first", "https://example.org/first"])
|
||||
def 'Look at the references'() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package extensions
|
||||
|
||||
import org.junit.Ignore
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class StackTraceTest extends Specification {
|
||||
|
||||
def 'stacktrace'() {
|
||||
// expect:
|
||||
// throw new RuntimeException("blabla")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Stepwise
|
||||
|
||||
|
||||
@Stepwise
|
||||
class StepwiseTest extends Specification {
|
||||
|
||||
def 'I will run as first'() { }
|
||||
|
||||
def 'I will run as second'() { }
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package extensions
|
||||
|
||||
import mocks.ItemService
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
|
||||
|
||||
class SubjectTest extends Specification {
|
||||
|
||||
@Subject
|
||||
ItemService itemService // initialization here...
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package extensions
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Timeout
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@Timeout(5)
|
||||
class TimeoutTest extends Specification {
|
||||
|
||||
@Timeout(1)
|
||||
def 'I have one second to finish'() {
|
||||
|
||||
}
|
||||
|
||||
def 'I will have 5 seconds timeout'() {}
|
||||
|
||||
@Timeout(value = 200, unit = TimeUnit.SECONDS)
|
||||
def 'I will fail after 200 millis'() {
|
||||
expect:
|
||||
true
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import extensions.TimeoutTest
|
||||
import spock.lang.Issue
|
||||
|
||||
runner {
|
||||
filterStackTrace true
|
||||
|
||||
report {
|
||||
issueNamePrefix 'Bug '
|
||||
issueUrlPrefix 'http://jira.org/issues/'
|
||||
}
|
||||
|
||||
optimizeRunOrder true
|
||||
|
||||
// exclude TimeoutTest
|
||||
// exclude {
|
||||
// baseClass TimeoutTest
|
||||
// annotation Issue
|
||||
// }
|
||||
|
||||
report {
|
||||
enabled true
|
||||
logFileDir '.'
|
||||
logFileName 'report.json'
|
||||
logFileSuffix new Date().format('yyyy-MM-dd')
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue