Jump to content

Unit testing & integration testing


TheGreyGhost

Recommended Posts

Howdy all

 

I've got a general question about unit and integration testing in Forge.

 

I'm trying to write unit tests for some of my new classes and it's proving almost impossible any time my classes refer to any of the vanilla classes such as EntityPlayerMP or similar because writing stubs or mocks for them is just too complicated.  All I really need is to override a couple of the class methods with stubs, but the classes generally don't have a default constructor which makes it a real pain.

 

Anyone got any tricks you can recommend?  I'm currently resorting to inserting my test harnesses into the mod code and running it like a normal mod, which is pretty clunky.  Surely there's got to be a better way?

 

-TGG 

 

Link to comment
Share on other sites

Wow! How refreshing to find someone who is at least interested in testing prior to deployment. Unfortunately, I've had the same problem. As a result, I have just decided that integration testing was the only alternative. Unit testing would be doable, if and only if the Minecraft and ForgeModLoad code was writable and substitutable in the test environment, which it seems not to be.

Link to comment
Share on other sites

:-)

 

Ha yeah I've learnt the value of automated unit testing the hard way... subtle little bugs that made my database lose every 1024th row of data,  introducing a memory leak while fixing a different problem that caused my app to crash after running for 3 hours, an object-copying mistake between two classes that made the player disappear everytime he moved left and pushed fire at the same time.  Having to re-do 3 hours of extremely boring manual testing, twice, when fixing another bug.

 

Anyway - I got a suggestion in another forum which I'm trying out now:

http://objenesis.org/tutorial.html

 

It lets you instantiate classes without calling any of the constructors.  The object is in an invalid state of course (all member objects are null), but you can override its methods with your own stubs, pass the instantiated object to your class under test, and it will call them no problem.

 

I've just tested it on EntityPlayerMP and it worked a treat.

 

-TGG

 

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • 🎰 Mainkan Slot Online dengan Hanya 5 Ribu Via Dana, Proses Cepat! 🎰 Buka pintu ke dunia hiburan tanpa batas di UANG69 Slot Online! Bersiaplah untuk merasakan sensasi kemenangan di ujung jari Anda dengan taruhan serendah 5 ribu rupiah saja, melalui metode pembayaran yang mudah via Dana! ⚡ Proses Cepat, Nikmati Keuntungan dalam Sekejap ⚡ Bergabunglah dengan komunitas slot paling dinamis dan terpanas, dengan puluhan permainan slot yang menakjubkan, serta kesempatan untuk memenangkan jackpot besar! Rasakan gemerlapnya Las Vegas langsung dari kenyamanan rumah Anda sendiri. 🔥 Keunggulan UANG69 Slot Online: 🔥 ✅ Taruhan Serendah 5 Ribu Rupiah ✅ Metode Pembayaran Mudah via Dana ✅ Proses Cepat, Penarikan Lancar ✅ Puluhan Permainan Slot Terbaik ✅ Jackpot Besar Menanti untuk Dimenangkan Bergabunglah dengan UANG69 hari ini dan jadilah bagian dari petualangan slot yang tak terlupakan. Nikmati keseruan, kemenangan, dan hiburan di ujung jari Anda! Jangan lewatkan kesempatan ini, bergabunglah sekarang dan mulailah memenangkan hadiah besar! 💰💎🎉
    • Hello, I am trying to play Minecraft (premium version) with the All Of Create mod from CurseForge. When I launch it from the Minecraft launcher I get an error "The game has stopped working" Error code: 1. I tried to create a modpack, without mods, and launch it (in case there was any incompatibility) but it doesn't work either.... Error with mod: https://paste.ee/p/zzvJY I hope someone can help me. Thanks in advance.
    • Jika Anda mencari maxwin secepat kilat, maka Slot Kilat77 adalah tempatnya! Dengan koleksi slot terbaik yang dirancang untuk memberikan kemenangan instan, setiap putaran di Slot Kilat77 adalah kesempatan untuk memenangkan hadiah besar dalam sekejap. Bergabunglah sekarang dan rasakan sensasi kemenangan kilat di setiap gulungan. Jadi, jangan ragu lagi, mari bergabung dan raih maxwin secepat kilat hanya di Slot Kilat77!
    • Jos77 adalah pilihan terbaik untuk meraih maxwin hari ini! Dengan koleksi permainan slot terbaik dan peluang kemenangan yang tinggi, setiap putaran di Jos77 adalah kesempatan untuk memenangkan hadiah besar. Bergabunglah sekarang dan rasakan sensasi kemenangan yang luar biasa di setiap gulungan. Jadi, jangan lewatkan kesempatan untuk menjadi pemenang hari ini di Jos77 Mulailah petualangan slot Anda sekarang di Jos77 dan temukan sendiri mengapa kami adalah pilihan utama para pencari maxwin. Dengan grafis yang memukau, fitur bonus yang menggiurkan, dan dukungan pelanggan yang luar biasa, kami siap membawa pengalaman bermain Anda ke level berikutnya. Tidak peduli apakah Anda seorang pemula atau ahli slot, Jos77 menyediakan lingkungan yang ramah dan menyenangkan bagi semua pemain. Jadi, bersiaplah untuk meraih maxwin dan nikmati kesuksesan Anda di Jos77 hari ini!  
    • BARBAR77 adalah destinasi utama bagi para pecinta slot online yang mencari sensasi paling barbar! Dengan koleksi slot paling mengagumkan dan peluang kemenangan yang tinggi, BARBAR77 menawarkan pengalaman bermain yang tidak akan Anda temukan di tempat lain. Bergabunglah dengan komunitas kami dan rasakan kegembiraan dari kemenangan yang mengagumkan di setiap putaran. Jadi, siapkan diri Anda untuk petualangan slot yang paling barbar di BARBAR77!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.