BananaPuncher714 / NBTEditor

A single class NBT editor for items, skulls, mobs, and tile entities
MIT License
138 stars 29 forks source link

Discussion about Unit Test. #13

Closed portlek closed 1 year ago

portlek commented 4 years ago

I saw that we probably can't use a real unit test with Jupiter because we don't have NMS classes so, maybe we can make a do-test.sh shell script that can download BuildTools.jar and set up a temp. server in test directory and then it can run a class that can test the project.

What do you think about that?

BananaPuncher714 commented 4 years ago

Github actions can be used to unit test, I think. This action can be used to build a server and then run tests somehow.

portlek commented 4 years ago

Github actions can be used to unit test, I think. This action can be used to build a server and then run tests somehow.

Alright nice, I will try to make an action script with that.

portlek commented 4 years ago

I finished the unit testing with GitHub action here; https://github.com/forkstuffs/NBTEditor the remainings are just writing unit test classes. image

BananaPuncher714 commented 4 years ago

Wouldn't it be possible to compile a jar with the test classes separately, instead of keeping the plugin inside the main directory?

portlek commented 4 years ago

Wouldn't it be possible to compile a jar with the test classes separately, instead of keeping the plugin inside the main directory?

I will add a profile that allows us to don't put plugin.yml and NBEditorTestPlugin.java class into the final jar(mvn-central jar), so it's possible with this design. But with test directory, nope I think it's not possible.

portlek commented 4 years ago

Ok done there are 2 profiles called test and maven. mvn clean package -Ptest is for including plugin.yml and Test classes. mvn clean package -Pmaven is for excluding plugin.yml and Test classes. So, you just need to use mvn clean deploy -Pmaven to deploy the maven central.

portlek commented 4 years ago

You can look at my p.r. that can create server and run. https://github.com/BananaPuncher714/NBTEditor/blob/7327e646a6e5ef0950863a0d698cffbed816a0e1/.github/workflows/maven.yml @BananaPuncher714

BananaPuncher714 commented 4 years ago

I tried that, but it gave me errors when it couldn't find the server jar. There is no other way to grab it without building it afaik.

I've been testing it on a separate branch, and this is what I'm planning on going with, unless you can improve it more. The workflow can be found here

This solution doesn't require having to create different profiles, nor does it involve putting test code in the main packages.

BONNe commented 4 years ago

Well, if you do it as UnitTest and use powerful powermock and mockito it is possible to do it in test directory without the necessity of server files (at least I think so).

But it would work well with Jenkins server. I do not know how it will like GitHub actions as they do not like external libraries very well.

I once tried with a simple spigot dependency and it did not work.

BananaPuncher714 commented 4 years ago

I'm not too sure about how well it would work, since NBTEditor does use reflection to access a lot of nms classes that wouldn't otherwise be accessible without the actual server.

portlek commented 4 years ago

I tried that, but it gave me errors when it couldn't find the server jar. There is no other way to grab it without building it afaik.

I've been testing it on a separate branch, and this is what I'm planning on going with, unless you can improve it more. The workflow can be found here

This solution doesn't require having to create different profiles, nor does it involve putting test code in the main packages.

Alright, don't merge the unittest branch into master unless we make more tests.