2

Like the title, I need to create a BLOB object for my unit test.

I read this

How to create BLOB object in java?

But it needs to connect to a specific database.

Thank you for taking a look.

1
  • 2
    Since BLOB is an interface, you could create your own mock/proxy which will facilitate your requirements Commented Jan 4, 2019 at 3:46

2 Answers 2

3

Since BLOB is an expensive resource and you are doing a test, mocking is a great way to create a BLOB.

Also with this, you can control what the BLOB is without actually reading through a large object.

How to do it depends entirely on the testing framework you are using. Example, this is how it is done in Mockito: Blob blob = mock(Blob.class);

Sign up to request clarification or add additional context in comments.

Comments

2

I think this way is ok:

byte[] bytes = "A byte array".getBytes();
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.