Reputation: 413
Like the title, I need to create a BLOB object for my unit test.
I read this
But it needs to connect to a specific database.
Thank you for taking a look.
Upvotes: 2
Views: 7966
Reputation: 413
I think this way is ok:
byte[] bytes = "A byte array".getBytes();
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);
Upvotes: 2
Reputation: 1082
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);
Upvotes: 3