问题
So there is something I'm missing here about how to use JMeter.
I was reading in the user guide that I can use a Java Sampler to run my test. It's ok because I need to read a file with some content in it and then send it to the storage engine.
So I was starting writing some unit tests to implement my version of a JavaSample using the class AbstractJavaSamplerClient.
I was counting to load the file in the setup just once, but it puzzles me the fact that I can;t pass it to the runTest method using the sampler context.
How do you do something like this? I mean, obviously if I lose time loading a file each time the test has no meaning
回答1:
Wouldn't it be easier to use __FileToString() function wherever it's required?
If you want the file to be read just one time Once Only Controller can be used to read the file into a JMeter Variable
If you're going to re-use the variable in multiple thread groups as vlns says it should be converted to JMeter Property as Variables scope is limited to current thread group only. See How to Use Variables in Different Thread Groups.guide for implementation details.
来源:https://stackoverflow.com/questions/25767654/load-a-file-content-to-be-used-in-a-test-with-jmeter-and-a-abstractjavasamplercl