IntelliJ IDEA Conf 2022 | Evolving JUnit 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] hi Mark how are you hey I'm fine thanks Floyd how are you I'm good thanks so uh you work at Gradle and you're a contributor or maintainer for junit so basically you're building You're Building all of the stuff that we use on a daily basis well some of it yeah so whenever there's a problem with testing I'm yes pretty much to play yes so yes uh all right so how did you get into uh contributing to junit because I read you were first an airline programmer and then got into Java how did that happen well I was working with Java before I got into erlang so that has a longer history um but yeah well we were working on Janet 5 I wasn't actually working with Java for for some time but what was working on the back end in Airline so that was kind of interesting so you were doing Java open source while working in in Airline for your day job yes functional Dynamic types you know during the day and then study types object oriented at night yeah basically pretty much okay okay because it wasn't challenging enough well it's interesting I mean I think it doesn't have like pattern matching like full-fledged pattern matching and things like this so definitely uh got me thinking yeah cool cool cool so you're going to talk to us today uh about evolving junit five and uh what we have to look forward to I guess yeah pretty much like like the highlights of what happened oh and yeah a few things that will come next as well well I love using J units so I look forward to learning more let me add your slides to the string and and I'll remove myself and have fun thanks all right yes I'm don't really have to talk much about this one right so I got into David quite a while ago um I'm not doing a team lead since 2016 actually and we had this whole crowdfunding campaign to get this thing started called Janet Lambda that was all like ancient history now because as of this September Janet 5 actually has turned five years old so it was launched like the fight with o release was in September 2017 and it's five years later already time flies and as you can see here we've been uh we've been busy so that would have been nine feature releases and also numerous patch releases in the meantime you can maybe see it the frequencies locked down a little bit um but we're still actively working on it of course and and also have some some more things in store that we want to work on foreign we're going to cover like how to write tests actually with junit I mean I think that's kind of obvious but also how to write extensions with junit um that's doing a Jupiter and then the second point is the general platform what is that why do we need it and then at the end we'll have some more resources to get you started and I'll also talk a little bit about like okay what's on the horizon what will be next for junit all right so first of all Jane the Jupiter the modern testing framework of java in yeah according to us at least so in Jupiter what is that it's an API for writing tests and extensions and it requires at least Java 8 so that hasn't changed since the 5.0 release and we've reactively testing it not just with Java but also with kotlin and groovy so that's also kind of supported or even though Java is something use case for us and we're trying to be a good citizen so it ships with Java module descriptors and also GI meta data so basically that all like the ecosystems can directly consume the jar files this is not just true for the Jupiter jars but for everything else as well thank you all right so what's the basics like what does a test look like in J unit and if you have ever written a test with Janet before this will look familiar right so you'll have to define a class in this example it's called tests and then you have to write a method and then annotate the test annotation if you're familiar with unit 4 what's different here is the package import this from this is now in a jupyter API package and the assertions on the assertions class in that same package and you will see many of the familiar assertions in that class but there's a few new ones like a certain throws that's your really fine granularity and assert exceptions and blocks or code that you pass Aslam does or assert all where you can check multiple conditions um it's not a full-fledged super flexible assertion library and this is so J there's hem quest for that you didn't want to reinvent the wheel but it has the basics um so you can get started with writing assertions um if you have special needs you can pull in an additional library and another thing that you might notice here in this example is there's no public Notifier it's a small thing but it's slightly a spoilerplate so you don't have to make your test classes public anymore and my other test methods there's also the lifecycle methods um so lifecycle method is something that is called in this case before each test method and there's also after each which would be called after each test method and before all and after all for something that you want to prepare on the class level and yeah these annotations they work like the similar annotations are doing it for so you can still use that style to prepare your tests but there's new things so one thing that's really really cool is display name so display name is something that lets you write natural language text as a string basically so you can put that on the class level or you can put that on the method level of your test and um yeah that's to be more expressive in describing of the test um is supposed to test what it's supposed to do right you're not just limited to the names in the method anymore catalogies only go so far there's things that you know like ignore but it's not called disabled and um there's also a more flexible way of tagging tests which is the tag annotation which just takes a string instead of a class literal but all all in all yeah the basics still look pretty similar but there's a nice few additions that come with Jupiter compared to doing it for and display names you can also take that a step further there's an extensible API that also lets you generate display names so in this example we use the built-in replace underscores display name generator and then that would generate a tree of tests in your IDE that would look something like this below right this one simply replaces underscores with spaces but you can write your own display name generator that you know takes a look at other annotations or whatever and you can also configure a default for all your tests uh via some configuration parameter that you can put in a properties file so it's applied to all your tests or you can specify it by a system property another new thing in Janet Jupiter is nested tests so here's an example where we test a stack um and you can see two levels of nesting here so this is the top level class called stack tests we have an essay class called when new and one that's called after pushing and this lets you build like a context basically yeah so we have a stack on the top level initially it's empty so we can write some new some annotations for the empty State then we push an element in this before each method that's only applied in this kind of second secondary second level nesting context and then all the tests in that nested class can use that state for example this was useful in some cases when you go into group tests where you have kind of similar setups or tear down a logic that you want to reuse um it doesn't have to mean that you have to use this in audio tests of course there's also some special support for kotlin so we have some top level functions of extension methods that we that you can use to write and yeah more idiomatic assertions in kotlin like as you can see here we have three Imports the first one just is the regular static method from the insertions class but there's two top level kind of functions here that we import from the jupyter API package and for example it starts rolls lets you use a vf5 kind of generics here to write this in a more kotlin friendly way and then you can yeah use this assertion um yeah easier than with just the standard Assad throws method if you have imported that and similar for us at all also that signal has in these little closures here so you can test that easily more easily another thing that's not just for kotlin but kotlin was a strong use case for it is the test instance life cycle so by default in genet4 energy of Jupiter it's the same you get a new instance of the test class for every test method so that ensures you don't have a default you're not relying on any kind of side effects one test has stored something in a field the next test can read it or something like this but in some cases it can get in your way and confidence one such case um for example here if you have it before all method and usually before all methods have to be static because we don't create test instance for them to invoke them at all but in kotlin it's really cumbersome to write a kind of a static method you have the companion object have to put jvm static on that on that functions that's really cumbersome um and this one lets you just change the life cycle that has instance per class here The annotation configures this differently and and here you basically you get one test instance where the entire life cycle of this test class which also means that the before all methods don't have to be static anymore I could just write the code in a more easy way foreign actually introduced was parallel execution so by default tests are run sequentially but you can opt in and change that and you can even make them run concurrently by default all of them and then you can use the execution annotation here to opt out if you want or you can do the other way around and opt in using concurrent and there's also some some basic kind of high level synchronization Primitives that you can use you can annotate your classes or methods with this resource log annotation here for instance uh just to declare okay I'm using this this thing with some key Either in read node or read write node and then jnet will ensure that node two tests the conflict with that resource would run at the same time so it's kind of like locking conceptually and there are there's even a more simple way introducing 5.7 which is the isolated annotation which basically if you have that on the method Janet will not run anything concurrently to that method it will only run this thing in an isolated way right as I said it's just the Highlights today otherwise I would have done a demo for this but time is too short but we have a demo coming up um namely more ways to test so we have seen a test method here but there's other things that you can do to testing to test your code so this is an example project that I prepared it's just using Jupiter here in the latest version and Java 17 um there's nothing not much else here to see and what I'm going to do is I'm going to create a new class called math tests and then we're going to create a test method and in this first test I want to test the square root function of the Java math class so I'm going to use this for equals and say okay I want to test that the result of taking a square root of 4 is 5 4 it's 2 with a Precision of 0 0 0.01 and yes I want to import this oh come on there it goes all right so this is like the first simple test this is nothing fancy but we've seen this on the first slide with the basics and I can run this test method here and as you can see here below it's green everything works okay with such a function you usually want to test it with more than just one set of parameters right so that's what we're going to do next so how can we write a parameterized test with Jana Jupiter and what I'm going to do here is I'm going to basically extract some parameters so we can see this kind of okay this is expected well it's actually the controller I'm sorry so this again and the other thing is expected all right so okay intelligent overtries it's warm me here and if you want to run a parameter rights test you have to use the pretty much test annotation that's one thing and then you have to tell Jane it whether the parameters actually come from there's multiple ways of doing this of course for here we're just going to use CSV source and use a text block to specify the CSV there's other other sources you don't have to use CSV of course but in this case we're going to do that so the input was four and we wanted to have two as a result we can run this and then we can see here okay 4.02.0 which is not very readable but we can adjust the name so we can say square root of the first argument equals the second argument here so like a message format and then we have square root of 4.0 equals 2.0 here as a result but it's much more readable and now we can easily add more like we can say nine is three or two or this one for one and then run this again right so we could easily add multiple um more combinations of arguments here of course so this is a very brief demo very twice tests moving on to the next example so here I want to write something that is flaky and usually you don't want to write this but sometimes you have something like this and then you want to kind of check is it flaky or what what's going on and my example see the example here I'm just going to assert that not random which returns a value between 0 and 1 is 0 with a Precision of 0.9 so let's run this screen what is it always green let's see so we can just repeat the test and easily run it 100 times and then we see okay test fail 8 of 100 failed so this is clearly flaky and I mean this case obvious why it's flaky but sometimes you have these tests in your production code basis and you're not sure if you have some concurrency issues still and this is just an easy way of running it multiple times all right let's move on to another example so we want to test that even numbers are divisible foreign all right so but we're not going to do this in a normal way we're going to use um test Factory so a test Factory method is something that Jupiter's provides it lets you create tests that's why it's called Factory so you need to return something in this case we're going to use a stream and the stream is a stream of dynamic tests so the first thing we need is even numbers and because I'm just going to use an in-stream for that I'm going to start with zero and we have if we have an even number um we're just going to add 2 to it to get the next even number right that's simple enough okay now that we have an even number we want to write our test for it and as we the first thing we're going to say is um we need to create a dynamic test and academic test has two parameters a string and an executable the string is the name of the test so we're going to say n is the visible by 2 that's the name and then comes basically the body of the test what would normally be the body of the test method and in our case we're going to assert that um yeah well and model 2 is 0 that means divisible by 2 in Java right and before you run this we should limit the stream because otherwise we get an infinite infinitely running test we don't want that here so we're just gonna say let's find a thousand a thousand of these and we run this we can see okay tests passed 1000 and we can see here all these kind of even numbers were checked everything is green um just to see it break I'm gonna use all numbers for change and then we should see having them failing right 500 failed so of course odd numbers are not even not divisible by two um So that obviously fails all right short recap of this so parietalized tests are really useful like they can have different sources so we've seen CSV Source here right but it's just one of them you can have the CSV Source in a file so for example in Source test resources or software we just use value source and Supply a list of ins or strings as um kind of parameters to The annotation you can use enum souls and pass the enumclass and then we'll get all the enum constants as inputs you can use method source to call a method in your test class or even some other Class via some name from any convention and IntelliJ also has some nice support for this for navigation and yeah you can of course also write your own provider so there's this argument Source annotation that lets you specify something else so you could read from a Json file or something else in a database whatever right um basically you have full flexibility with this and then also we've seen the repeated tests um then useful mostly for flaky tests and then just trying and seeing if this is really stable or not and test Factory to produce Dynamic tests or just kind of see the tip of the iceberg there can even Nest them with Dynamic containers and things like this but yeah that's not something we have time to do today so that's very brief how you write tests using internet Jupiter um I also want to talk a little bit about extensions in Jupiter so why would you want to write an extension well you want to extract some behavior that you want to use in kind of multiple tests in in some reusable way right you could of course create some super class for your tests but that doesn't really scale you can't you can only have one superclass so extensions are way around this you can have a kind of extensions as multiple as many of them registered at the same time as you need they should not conflict with each other and this is fully supported and they allow you to hook into the test Discovery and also the execution you can you know change the behavior of taking it this way and ultimately what this allows is to have more concise tests and make it simpler to write them so let's see an example so the third example here is we have a test and we want to disable it on certain weekdays like today it's Friday right and um I'm speaking at this conference so I don't want to be interrupted by tests um that are failing um so if I run this now this fails because I have payout here and it says fixed me so why does it fail well obviously right but I have to disabled on weekdays here does this do anything what is this even so this annotation is just defined here locally as you can see here it's in the same package it's here um just an annotation with runtime retention and Target methods nothing special right so actually this is not implemented yet so we've got to do this right we're gonna say we want to register an extension whenever this annotation is present we want to register our extension that disables tests if the weekday is actually one of those weekdays specified in The annotation so let's do this you can of course implement this as a top level class I'm just gonna do this in here for sake sake of simplicity so Toby don't have to jump around as much right so it's in here and you can see intelligators are picked up on the need to implement extension but extension is only a marker interface as you can clearly see here right there's nothing in here if you look at the hierarchy there's lots of sub interfaces and for now I'll be interested in this one execution condition so that's what we're going to pick here and you have to include one method for this which is called evaluate execution condition and it gets an extension context so it the extension context itself and that's something that most of these kind of extension interfaces and the methods that you have to implement get as a parameter it allows you to see okay what am I currently about to execute like what is this what's the display name of this test what are the tags what's the test class and so forth what's just instance right you can you can basically look at all of these things and then decide on what you want to do in our case we want to look at for this annotation actually here that begin right so that's what we're going to do and there's a support class we can use for this called annotation support so we're going to get the annotated element out of that context it's an editing element which is the superclass of kind of the reflection API for a class in Java or a method so basically once when you use this we're already making sure that we're not depending on whether this annotation is declared on a class or on a method foreign get back an optional maybe The annotation is present maybe not so let's say it's present then we want to map it and then we want to filter so we want to check the day of weeks that we have in The annotation if any of them match today and today we get from local dates now let's get this day of the week it's getting a bit unreal ideas let's extract this to a local variable current day of week fantastic import here okay so we filtered now if that's the case we have an optional that is not empty we don't really care for the value so we can ignore that but we need to return a condition evaluation result and what is that it's basically a Boolean this enabled or disabled with a string namely the reason for it being enabled or disabled so in our case it's simple if the day matches um one of those days in The annotation you're going to return disabled and we're going to say today is that day otherwise is going to return foreign just need to return this all right going back to the demo test class so when I run this now it should be successful because the test was skipped and it even provides the reason here because today is Friday right just to double check let's say it's Saturday any notation and then the test would be executed and failed because it's not actually Saturday it's Friday all right that was the really short demo about extensions um like we saw in the we've seen the extent with annotation um to register an extension but there's actually multiple ways of doing that um you can use extend with classes and methods we've used it on a method indirectly via some other annotation but you can also use it on fields and parameters since Janet 5.8 so you can have a parameter on your test method that specifies something and then it can automatically register an extension that you know performs the injection for that parameter for example you can also use the register extension annotation if you want to have some control it has some parameters to the extension classes Constructor for example you would programmatically instantiate this extension on a field of your test class and then use the register extension annotation for that the Third Way is you can also register extensions globally so then you need to get registered up by the service loader mechanism of java and you also need to set some opt-in flag to to register Global Extensions by a configuration parameter that would allow you to register extension for all your tests without even mentioning it in the source code even once we've seen this extension implementation there's a marker interface called extension but there's actually a lot of sub-interfaces for this and the important thing at the point I want to make here is if you implement an extension you can Implement as many of these sub-interfaces as you want they are composable so for example you could implement it before each callback and then after each callback to do something before and after once clean this up again um so there's a lot of these extension interfaces this would be worth a separate talk so I'm not going to go into any detail on them just know that they're there and there's a lot of documentation also and examples um by now that you can take a look at there's also some Support classes so if you want to implement an extension there's help we've seen annotation support if you want to look up annotations on the test method or test class there's also a class called reflection support that you can even use to scan the class path for something or execute a method on your test class or whatever right whatever you can think of in reflection terms you can do with it one thing that annotation support provides you is a way of looking up annotations not just in a regular way but also um looking up composed annotations what is a composed annotation well we already seen one basically we've had this disabled on weekdays annotation here we added the extent with annotation but you can add additional annotations to that so for example here we also added the tag annotation and these two annotations are used to compose this annotation that is defined and I use this meta annotations in this case so this means whenever Janet sees a disabled on weekdays annotation on a test method or test class but you're actually looking for an extend both annotation using annotation support Janet will find it so that that's some added benefit that you would get using those Support classes there's also a lot of built-in extensions I'm really going to talk about them as well so temp tier support is one that's often useful if you want to work with files you need some kind of temporary directories and tempt user declarative way of injecting attempt here for example into a method as an annotated parameter you can also use a field of course it supports multiple tempt users since five foot eight so you have two parameters here with temp here you could get two of them and you can even configure the cleanup node since 5.9 so for example you configured by default it cleans up all the files in the temp there but you could change that never clean up or to only clean up with the test or successful for example if it failed you might want to look at those files and see what actually happens another thing that's built in and also implemented using extensions is timeouts so that's since the beginning since 5.0 there was a timeout um assertion method right that that's the kind of third timeouts within a code block within a test but since 5.5 there's also this declarative way of defining a timeout using an annotation and you can put the timeout annotation on a test or a lifecycle method and um you can also configure which thread it gets executed in the test that is um which is important for some detailed use cases but the clue is like if we want to ensure for example on CI that um all your test methods use some rather large timeout so they don't kind of you know let the build run indefinitely you can even configure that globally now via this configuration parameter and enforce the time some Timeout on all of your methods unless they override it of course foreign execution conditions like the one we implemented but in a more meaningful way so for example you can disable or enable test space on the operating system the JRE and other things but one thing that I wanted to point out here is also the architecture something that is news in hybrid 9. yeah now that M1 Max basically are kind of ubiquitous this is something that has become important to check for the architecture for example on some tests because sometimes you have native libraries and sometimes don't work on some architecture or only work on some architecture there's also built-in conditions for web check system properties um or environment variables for some value some brackets that you can apply here there's enabled or disabled if which lets you specify a method reference that would be called and has to return basic whether or not this should be enabled or disabled and just recently like python I release which was last week we added this enabled or disabled in Native image annotation so if you use crawl VM then this would basically able disable your tests depending on whether the test runs in the native image foreign also there's a lot of third-party extensions I want to point out a few here this Dana Pioneer which is a project that is kind of associated with j in it in a way um so we closely collaborated with the maintainers of that project they basically want to provide an extension pack for jnet with a mixed set of extensions it's also a very great support for spring here there's some keto test containers all of that and we collect these extensions actually on this Wiki page so if you if you know of one that's not on this list or not on the Wiki page which has the complete list please let us know or edit yourself to the Wiki page foreign so that was the first um item on the agenda how do I test an extensions using genet5 um I think we have some time to possible questions if there are any hi Mark um honor our moderator is doing a great job of answering questions in the in the chat so I think we don't have any uh open questions at the moment and also um Christian Stein is in the chat answering questions a question from the juices so they have new covers and and you can just continue great all right yeah I'll do that all right cool yeah it's always nice yeah if the team chimes in on the chat thanks Christian all right so I can hardly do a talk about unit 5 and not talk about doing a platform so this is next when we set out to kind of redesign how Janet Works um we had this separation of concerns in mind we wanted to fix some problems we had with Janet 4 which was just this one jar file which was really not that great at you know maintainability and everything so um we wanted to separate the constructs namely the first concern is obviously you want to write a test and extensions so you need an API to do that but that should be separate from the way you run things so we also needed an API on the other side which is the third point on on the slide for execution of tests by tools like Ides and build tools so that's the launcher API that we'll see in a minute so these two should be clearly separated and in the middle we need something that knows about okay what is actually a test and an extension and um so that would be called by this launcher to discover an extra tests and it should be extensible because we wanted to support multiple ways of writing tests we wanted to be flexible in the future and we also wanted to allow that people could write um could run unit four tests and doing three tests even on the new platform while also being able to write Jupiter tests and run them at the same time so on a very high level the architecture looks like this so um you have IDs and build tools in the bottom of this picture and they use the platform named the launcher API and then you have these colored boxes like vintage and Jupiter third party here which are actually engine implementations but also kind of tie into the platform but there's no direct kind of dependencies from The Ides and build tools to those engines it's all decoupled so let me say J at 5 actually mean Jupiter and vintage and platform and vintage actually is the engine that lets you run in a three internet forecasts but there's also other engines so Spock framework I recently wrote one for test NG there's other kinds of test engines like jquik which is for property based testing cucumber a bunch of engines for kotlin like code tests and lots of others and we also collect them on this weekly page so the platform is really open for extension and you can even mix engines in one test run so this is an example from the retained samples people you can see a test Tree on the right here and this so This is actually mixing um I don't know seven eight test engines here and a single test run um you normally wouldn't do this obviously right um you could use this to for example gradually migrate from one test engine to the other so for example you might have an old project but the tests were written in genet4 and you want to write the new test engineer Jupiter what do you do do we have to migrate all of them at once no you actually don't have to do this you could write a new test in Jupiter and then if you want you could gradually migrate the old tests or there's even use cases where it makes sense to have multiple um test engines going forward like you could use ARC unit to write architecture tests or a cucumber to write more kind of you know user-facing tests and you see something else for your unit tests and it would be perfectly plausible to do this and the general platform allows you to run and mix engines and get all the results in a single test run a new feature in 5.8 is the declarative test Suites and this is actually also implemented as a general platform engine so the sweet engine and it allows you to define a class and add the suite annotation to it and then you can basically select the test you want to run you have all the selectors that the general platform supports like packages classes directories files class path resources modules everything you can also Define a couple of filters in this case we're filtering by class name patterns so we all we only want to run classes that end with tests and that's it you can run this and the general platform Suite engine will pick it up and the result will pretty much oh that was the wrong would pretty much look like this which actually the three test stars that we see here at the top node is actually such a sweet class that is executed using a suite engine another thing that the platform provides is on text expression filtering so you can precisely specify which tests you want to run based on tags you can use this to include tags that will exclude tags and as you can see down here we can use Expressions so it could be just one tag which is a simple kind of the simplest expression um possible but you can also use kind of Boolean operators here and say I want to run all the tests that attacked with smoke and feature a or not with smoke and feature BD right so you have lots of flexibility here to precisely specify which tests you want to run you could use this for example to separate your unit tests from your integration or functional tests and have different test tasks or different targets for that another thing that the platform also contains is called test kit um this engine test kit class allows testing extensions that we've seen or even test engine implementations for its name actually comes from in tests so it's an API that you can use in your tests to run tests so here basically is the entry point you say okay we want we want to run a test using the DNA Jupiter engine we give it selectors so this is a little bit like what we've just discussed on The Suite class in this case we want to select this sample test case class for running and then we say execute and what we get back is a collection of results and it records all the events that happened during test execution and we can use that to write assertions for such tests for example here we're using those assert that events have exactly one event uh where it's a test with skip tests in its name and it will skip for a certain reason so for example if you have written an extension that would use this reason in this condition evaluation result that we've seen earlier you could test your extension with this and last but not least since 5.9 is actually a new XML reporting format finally and this specification for this is called open test reporting it's in a separate repository so we've really tried hard to keep it even independent of J init and independent from java even so the specification is in a separate repository under the um open test Alliance organization on GitHub um yeah and we've written a kind of defaults or kind of demonstration implementation in June so it's really simple if you want to use this and then try it out to to do so all you have to do is basically set the system property on your test jvm to true or specified as some by some other means as a configuration parameter and the idea of a new format is that it has full support for all data platform features such as hierarchical tests structures display names tags and all that metadata that is really helpful when you want to reason about test results and it also should be extensible so we want to really have to swarm it um it can be extended by additional XML schemas and it allows you to be kind of precise what things mean you know schema specifications um there's actually two formats so the first one is rather technical which is this one so this is from an example test run that ran one test method flat default in a nested class demonstrate Polaris tests in the top level colorful Let's test class using the general Jupiter engine and you can see there's like a started event for every level and a finished event as well so the IDS kind of match here right um but it's very technical so this is not something you would want to look at when you want to reason about your tests um even with a good XML editor yet you would have to kind of yeah kind of match these IDs in your head or you know you search to find them or something like this um and this is not it's actually by Design right this is not designed to be very human readable it's designed to be easily writable by um any kind of testing framework so as soon as something started the testing program would write a line started as soon as something's finished it would write a line finished and that's it it wouldn't have to buff or anything at all that's the idea right so because this is not very human readable that's actually a second format which we call the hierarchical format which we open test reporting repository provides a CI tool as a reference implementation one this can actually convert from this event-based format to this regular format and this is very a very rich format and it's it's nested it's a racket call so basically here the root is the engine and a Jupiter and you can see there's a child here which is this color palette tests and this one has another child which is the demonstrate polyps test which is the domestic class in this case and that is another child which is actually the flat default method is it a method yes you can see it uses a Java method source yeah here's the class name and see how it's in its nested class and the method name is fat default and you can also see there's full support for display names and um even you know you still have to have to have means to get stuff like unique ID from j in it or um yeah even like the type of things and provides with a summary and you know if you have a decent pixel editor you can actually use this and look at it and reason about it it's not as opaque as the other one of course this can also be used to generate some HTML report or whatever right in the next step so this is relatively new and if you haven't seen it yet which you probably don't have please try it out and we're looking for feedback on this um is there anything missing is there anything kind of over engineered about this please let us know we really want to know all right that already concludes um the platform part and yeah I'm going to give you some some resources and talk a little bit about what's next for J unit so on the horizon uh we want to keep working on this reporting format so we want to add support for attaching files for example screenshots or device logs for for example if you have some Android tests or something like this so it really should capture everything that is needed for such a reporting format to make sense of why it has failed for example and there's a long-standing request to add an extension API for customizing the class load I used for tests um there's there are some use cases for this um yeah this is something we finally want to address and we also want to add support for perimeterized test classes so we've seen parameterized test methods earlier but sometimes it really makes sense that all your test methods should be run with the same parameters and we don't want to repeatedly you know specify parameters test annotation and the same Source all of them you would really like to for me to write the whole test class with those you know sets of arguments so that's something we want to look into as well and I already mentioned this new enabled or disabled in Native image annotation that we recently added to Jupiter and there's some more things that have come to our attention that we could do to be a better citizen in the ground native image space right now we have some of course we use reflection there's no way around some of these things um but there's some classes that we could write into the different ways so they wouldn't require kind of early initialization during runtime in gravity M basically some things like this and that we really want to improve upon and yeah so it's less work for other people basically and of course it's an open source project so it is and will always be open for any ideas you might have um I will talk about how to get ideas to us in a minute but that's still the case all right some resources to get started um so there's a very good user guide and just yesterday it's a nice short link for this so this is the first time they're publicly unveiled apart from the Tweet yesterday so if you want to go to the user guide it's simply docs.jnet.org and the user guide covers mostly Jupiter but also some platform aspects and um yeah we keep improving that over time and of course if you something see something missing in the user guide we would also be interested on feedback for that all right um what's next well that's all the sample projects so the start gmail.org actually points at the GitHub repository that contains sample projects for the most commonly used build tools um and yeah basically if you haven't done any James Jupiter development yet that's where you should go and just get started it also contains this example I showed previously with the portable engines that you can run in a single run so if you want to see that I'll also give it a call of course it's also javadoc api.jamin.org has that yeah so today's example code I will push that to GitHub later it's not committed yet but I will do so after the session so that should also also be available um for you to browse and yeah take a look at and play with if you want yeah we have some questions so now are there any questions now as Christian already asked about it not only Christian was here but also Sam and Juliet and they have been extremely active answering all the questions it has our Anna um there was uh some people were wondering about uh converting junit four to five in a large project um do you have any tips for them yes I think I have actually been multiple um project on GitHub that I have done this um I think the latest one I know of is actually open rewrite guys that have written kind of a converter that um as often we write I think it's a framework that supports basically General AST Transformations on large code basis and they've written some conversion also from genet4 to genet5 or Jupiter basically um I I can share the link on Twitter later and then yeah we should find it yesterday I I have noticed that I haven't used it so I was wondering whether any of you have experience with it well I tried it out on a sample project once at what time but um I can't speak to like converting a big project of course sorry yeah same um and uh so I know that we have some uh videos on it on our Channel or we have a video on migrating from junit four to five on our YouTube channel uh that I linked to in the chat already and we have tools also in IntelliJ IDEA to help with that uh Anna mentioned um right at the start of your tool people were asking about using junit 5 assertions versus using a search J in hamcrest and you mentioned that you didn't want to reinvent the wheel and I think also Christian said um that you also use a search J so basically you're saying we have we kept the assertions in junit five basic and you can extend them with additional libraries is that correct exactly yeah it's a basic set so you don't have to pull and get another Library when you can start it but if you want to you know write things in a more readable way at some point you might want to consider using something else so that's why we use it so J for our own tests as well yes perfect um I really liked your explanation about uh nested tests so uh because I've seen them but but never written them myself so basically I think it gives you a way to combine multiple paths is that correct so you set up for example in this case do this and then you can add uh yes let me get back to that slide yeah yeah we have a few minutes so I can take this and even copy it somewhere here so we can not sure if that's an intelligent box ldx is released so that's okay anyway okay so yes so let's run this to fixing all the Imports um so this is yeah a relatively kind of simple example right um so what this does is you can have kind of something that you for example when you right you had you can have multiple tests on this level as well in this case it's only one that just checks okay if it's empty what should happen you could easily write another one like um I don't know when [Music] I don't know it's one operations called pop or something on it so let's when you call this I think it should follow exception right so you can write this um what is it a little State exception I don't know see the tests tell us ah I don't want to insert an emoji sorry about that okay there we go yes no I should have that so oh it's an empty stack exception okay that's the wrong exception now ignore that Stacks in Java yeah I think we've been we've all been learning uh accidental things as well I noticed people in in the chat saying about using an underscoring numbers for readability that you use somewhere and and people saying that they didn't know that um it's one of my favorite it's one of my favorite things from watching other people's code repair programming or or programming in a group you see people use stuff oh I didn't know that was possible so I'm really loving that uh that today yeah that's cool I mean okay let me see if there are any open questions someone asked about testing concurrent code where end States might not be deterministic due to race conditions which is you know fun times do you have any tips for them yes I mean that's of course more tricky testing problem um but I mean Java has plenty of things that work there like for example synchronizing things using a countdown latch or using futures or even completable future I don't have any tests handy right now um but actually I've read a lot a lot of such tests at work because I'm working on things like test distribution at Gradle and there's a lot of kind of concurrency going on there so definitely it's the same testing problem whether you use DNA Jupiter or some other testing framework basically you basically have to rely on a Java's kind of synchronization Primitives and one thing that I think I use a lot is completable Future and then count on that to kind of wait on things rather than you know that sleeps it should probably stay away from those yes yes sometimes you do need them but overall I try to avoid and eliminate those um well I think we're running out of time do you have any famous last words or anything you want to share two or three more slides that I want to to go through so a few other questions kind of have stopped now that's that's fine that's totally fine yeah um I just wanted to point out yeah there's other ways of asking questions for example stack Overflow has it in a pipe tag which we um look at occasionally as well and but now that the user base is also yeah large enough basically that the questions kind of answer themselves so that not the Janet team has to be involved there at all times of course if you find something if you have any kind of feedback we would love to hear from you um there's all GitHub projects which you can just use to open an issue um there's also a chat tool abuse which is called guitar which also has a lot of community members in there so you know just probably go there and this last but not least a Twitter account for the Janet team as well so um there's multiple ways of interacting with us um for sure perfect and I also want to take the opportunity to to thank some of our sponsors or all of our sponsors um so you can actually sponsor J unit and IntelliJ is one of the sponsors for example um yeah this is just something if you use Jane it a lot and kind of your employer benefits from it you might want to consider you know becoming a sponsor so we're open for that as well basically that's um it's really great to have support from the community in this way as well um after all kind of funding open source is kind of an unsolved problem um but we are kind of making some Headway on this so so does that mean that uh you're also getting paid to work on junit or some people are yeah it's not like we collect huge amounts of money um you can click you know use that money for that to some extent and we also want to meet as a team early next year and you know just pay expenses and things like this so we can meet for a week somewhere co-located so uh we can you know work together and have that experience as well perfect well I learned a lot thank you so much Mark I think for my J unit use in the past I've merely scratched the surface I saw some really interesting things that I can't wait to try out uh so thank you very much for joining us today and sharing your knowledge um thanks for having me thank you so much hi all right have a good weekend bye [Music]
Info
Channel: IntelliJ IDEA by JetBrains
Views: 2,641
Rating: undefined out of 5
Keywords: intellij idea, javaFX, intellij idea conf, Kotlin, Kubernetes, Spring, junit 5
Id: EQPr7OhG768
Channel Id: undefined
Length: 59min 30sec (3570 seconds)
Published: Tue Nov 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.