rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

How i test my bot ? #315

Closed damorosodaragona closed 6 years ago

damorosodaragona commented 7 years ago

Hi, i have a class MyBot that extends TelegramLongPollingCommandBot implements LongPollingBot, know i want write test, i have try with Mockito but i can't understand to use it for testing the bot. I have find an example test class here https://github.com/addo37/ExampleBots/blob/master/src/test/java/org/telegram/examplebots/ExampleBotTest.java but it work only if i use AbilityBot API, there is a way to do this without using that API?

Clevero commented 7 years ago
  1. Why do you extend TelegramLongPollingCommandBot and implement LongPollingBot? You only need to extend TelegramLongPollingCommandBot.

  2. The easiest way would be to create instances of Update, fill it it that it fits your needs(chat id, message text, etc.) and then pass it to onUpdateReceived

damorosodaragona commented 7 years ago

1) you are right! Since know i have used old api, and with old api you must extends TelegramLongPollingBot and implements LonPollingBot. 2) I have try to do it, but when you create an istance of update you can't set the message or the chatID or anything else.

Clevero commented 7 years ago
  1. I don't think so. When I remember correctly it was never needed to implement something like LongPollingCommandbot. I also double checked it it as I tried to search for something like that in the old Tutorials and examples. Could you please provide me a link for that kind of information?

  2. I will try to make you an example

damorosodaragona commented 7 years ago
  1. Ok, maybe i'm wrong, I have checked but in the examples there isn't a class that use that interfaces. I don't know why i have added it.
  2. Thank's so much. I have do this: test(){ Update update = new Update(); } but i can't understand how set the fields which i need, because i find only getMethods on update object.
rubenlagus commented 7 years ago

Hi @damorosodaragona , have a look at those tests: https://github.com/rubenlagus/TelegramBots/blob/master/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java