# Painless unit testing

**URL:** <https://discuss.elastic.co/t/painless-unit-testing/83317>\
**Category:** Elasticsearch\
**Created:** [April 23, 2017, 10:19am UTC](https://discuss.elastic.co/t/painless-unit-testing/83317 "2017-04-23T10:19:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jillesvangurp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jillesvangurp/32/3863_2.png) [@jillesvangurp](https://discuss.elastic.co/u/jillesvangurp)\
**Post date:** [April 23, 2017, 10:19am UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/1 "2017-04-23T10:19:06Z")

</div>

I spent way more time last week than I would have liked to getting a few lines of painless script to work (not quite as painless as advertised). A lot of my pain came from having to relaunch our integration tests repeatedly. One thing I was wondering about is how to unit test this stuff.

On paper this stuff is perfect for unit testing: limited set of parameters and the output  
is a double. Except, I'd need some way of running the script and getting my hands on the output and I haven't really found any.

So, Is there any way of doing this with a proper unit test that does not involve depending on a gazillion ES internals or having to write a full blown integration test against a running cluster?

Ideally, painless would be available as a separate dependency that people can just pull in and use in their unit tests or wherever.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [April 28, 2017, 2:54pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/2 "2017-04-28T14:54:06Z")

</div>

One day you will be able to run painless outside of Elasticsearch but it won't have access to Elasticsearch's types then so every call to `doc['foo'].value` is going to do a different thing. You'd be able to much it up if you like but that won't catch differences between Elasticsearch's behavior and the mock. If that is ok with you then know that something is coming.

I don't think unit testing Elasticsearch and painless together is a thing that we'll support outside of the Elasticsearch project itself. Personally when I work on these issues I run Elasticsearch and use Kibana's dev tools to run the script over and over again. Once it is sound I move to to integration testing.

---

<div class="post-metadata">

**Author:** ![jillesvangurp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jillesvangurp/32/3863_2.png) [@jillesvangurp](https://discuss.elastic.co/u/jillesvangurp)\
**Post date:** [April 28, 2017, 3:22pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/3 "2017-04-28T15:22:58Z")

</div>

I think it would be ok to not have direct access to elasticsearch internals. I'd expect to be mocking external things in any case using e.g. mockito in any case. The key thing is to be able to verify that scripts compile and run and produce expected ranking score given certain parameters.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [April 28, 2017, 5:54pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/4 "2017-04-28T17:54:49Z")

</div>

Then you have to do nothing more than wait a while. We'll get there. But we're not sure when.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 26, 2017, 5:57pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/5 "2017-05-26T17:57:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 26, 2018, 8:18pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/6 "2018-11-26T20:18:53Z")

</div>



---

<div class="post-metadata">

**Author:** ![monde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/monde/32/29708_2.png) [@monde](https://discuss.elastic.co/u/monde)\
**Post date:** [November 26, 2018, 8:38pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/7 "2018-11-26T20:38:01Z")

</div>

I was on a project recently where our java plugin was doing scripted updates and we were using ESClientYamlSuiteTestCase to handle our integration tests in yaml. They were failing as integTestCluster uses the stripped down integ-test-zip for the integration test node (it only ships with netty transport modules). I discovered setting the distribution to "zip" in integTestCluster in our build.gradle will load up a standard node with the common modules like lang-painless, etc.

```
 integTestCluster {
  distribution = "zip"
 }
```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 26, 2018, 8:43pm UTC](https://discuss.elastic.co/t/painless-unit-testing/83317/8 "2018-11-26T20:43:33Z")

</div>


