Skip to main content

File asserts and manipulations with SoapUI and Groovy

Very quick one, re adventures with SoapUI and Groovy.

Have recently been building tests which need to run batch jobs and then assert against their output within the file structure. Below is a simplified implementation of what I've been up to:

//Build the file name to look for


def date = new Date();
fileName = "OutputFile" + date.format('ddMMyyyyHHmmmss') + ".csv";
folderName = testRunner.testCase.testSuite.project.getPropertyValue("sftpPath");
filePath = folderName + fileName; 
log.info(filePath);

//Read in the data
def inputFile = new File (folderName + fileName);

//Create a new list for asserting against
assertList = [];

//Populate with Contents of Text File
addContentstoList = {assertList.add(it)};
inputFile.eachLine(addContentstoList);
log.info(assertList);

//Assert the number of records in the array, plus for the existence of a specific object
assert assertList.size() == 5;
assertCustID = assertList.any {3};
assert assertCustID;

Found this simple and effective. As an added bonus, this creates and deletes directories and builds CSV files from lists:


//Create New Directories
def inputDir = new File("C:/temp/in").mkdir()
def outputDir = new File("C:/temp/out").mkdir()

//Create an Array for Inputs
def inputFile = [
    [id:'1',description:'One'],
    [id:'2',description:'Two'],
    [id:'3',description:'Three'],
]

//Create a csv file
def BuildFile = new File("C:/temp/in/team.csv")
inputFile.each {
    def row = [it.id, it.description]
    BuildFile.append row.join(',')
    BuildFile.append '\n'
}

//Copy to output folder
def sourceFile = new File ("C:/temp/in/team.csv")
def destinationFile = new File ("C:/temp/out/team1.csv")

sourceFile.withInputStream { is -> 
  destinationFile << is 
}

//Finally delete to tidy up
def delInput = new File("C:/temp/in").deleteDir()
def delOutput = new File("C:/temp/out").deleteDir()




Comments

Popular posts from this blog

A Lone Tester at a DevOps Conference

I recently had the chance to go to Velocity Conf in Amsterdam, which one might describe as a DevOps conference. I love going to conferences of all types, restricting the self to discipline specific events is counter intuitive to me, as each discipline involved in building and supporting something isn't isolated. Even if some organisations try and keep it that way, reality barges its way in. Gotta speak to each other some day.

So, I was in an awesome city, anticipating an enlightening few days. Velocity is big. I sometimes forget how big business some conferences are, most testing events I attend are usually in the hundreds of attendees. With big conferences comes the trappings of big business. For my part, I swapped product and testability ideas with Datadog, Pager Duty and others for swag. My going rate for consultancy appears to be tshirts, stickers and hats.

So, lets get to it:

3 Takeaways

Inclusiveness - there was a huge focus on effective teams, organisational dynamics and splitt…

Wheel of Testing Part 2 - Content

Thank you Reddit, while attempting to find pictures of the earths core, you surpass yourself.
Turns out Steve Buscemi is the centre of the world.

Anyway. Lets start with something I hold to be true. My testing career is mine to shape, it has many influences but only one driver. No one will do it for me. Organisations that offer a career (or even a vocation) are offering something that is not theirs to give. Too much of their own needs get in the way, plus morphing into a badass question-asker, assumption-challenger, claim-demolisher and illusion-breaker is a bit terrifying for most organisations. Therefore, I hope the wheel is a tool for possibilities not definitive answers, otherwise it would just be another tool trying to provide a path which is yours to define.


In part one, I discussed why I had thought about the wheel of testing in terms of my own motivations for creating it, plus applying the reasoning of a career in testing to it. As in, coming up with a sensible reflection of real…

Getting started with testability

At TestBash Netherlands, I said that, in my experience, a lot of testers don't really get testability. I would feel bad if I didn't follow that up with a starting point for expanding your mindset and explicitly thinking about testability day to day, and making your testing lives better! 

In large scale, high transaction systems testability really is critical, as compared to the vastness and variability of the world, testing done within organisations, before deployment, is limited by comparison. We need ways to see and learn from the systems we test where it matters, in Production.
Being able to observe, control and understand is central to testing effectively, and there are loads of resources and experience reports out there to help. I was/am inspired by James Bach, Seth Eliot, Matt Skelton, Sally Goble, Martin Fowler and a little bit of PerfBytes/Logchat, so lets see if it works for you! 

Overall Model:

Heuristics of Software Testability by James Bach

http://www.satisfice.com/tool…