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

Testers Guide to Myths of Unit Testing

One area that testers might be able to enhance their contributions to software development teams is how we perceive and contribute to unit testing. I believe testers busting their own illusions about this aspect of building something good would bring us much closer to developers, and help us realise what other layers of testing can cover most effectively.

Also, I want to do a talk about it, so I figured I would test the premise, see if potential audiences were into it. I put this on Twitter:
Working on a talk about what testers might believe about unit #testing & how we interact with developers creating unit tests. Any challenges/additions for my list below? #development#agilepic.twitter.com/4oT5HE4qs3 — Ash Winter (@northern_tester) December 19, 201730 replies with ideas tends to indicate that people might be into it. 
The ListI thought, as my final blog of 2017, I would provide a super useful list of the myths and legends we as testers might believe about unit testing:
That developer…

Why do Testers become Scrum Masters?

It was late and I was stuck on a train, so I pondered on the question of why do testers often (in my experience) become Scrum Masters. Its a very dear question to me, as its been a big part of my career journey In fact, I've been there and back again. Tester to supposed-to-be-testing-but-being-a-Scrum-Master to Scrum Master, back to Tester and very happy thank you.

I encapsulated my reasoning in the following:
Long train delay, decided to think about a thing. :) Why do testers (in my world anyway) often become Scrum Masters? #testing#agile#scrumpic.twitter.com/FGGXFiBGz1 — Ash Winter (@northern_tester) February 13, 2018The tweet got a lot of traction, and generated a couple of interesting threads which made me think.
Great list. Personally I think that as a scrum master I can add even more towards the goal of quality. — Christian Kram (@chr_kram) February 13, 2018 Perhaps part of the reason for the transition is a growing appreciation of where quality has its roots? If testing i…

Wheel of Testing Part 3 - Applications

I've only had to quit two jobs to finally find the time to finish this blog series. Winning at life. If you need reminders (like I did) check out Part 1 and Part 2 before reading on...

After the first two blogs regarding the Wheel of Testing, I was delighted to receive a few requests for the wheel itself, which got me thinking about applications of it, beyond what its original intent was, which I've explored in detail in part 1 of this series of intermittent blogs. Most models need a little air time to show their value, in software development we crank out models all the time, but I'm not sure how many get used. I am inspired by models such as the "Heuristic Test Strategy Model" by James Marcus Bach, as I have used it and seen the benefits it has brought for my clients, particularly the ability to ask questions. So, I wanted to create a model which has a number of use cases, both real and imagined:

Helping to unlocking a career in testing which may be stuck

It is no…