Flutter: Running integration tests breaks unit tests - flutter

Recently, I ran into an issue at work. To summarize it, I am currently working on writing test cases for an internal Flutter project. This had been working fine for a while, but after my summer vacation, it started breaking. It took me a while to figure out what roughly was going on, but I hen discovered that running integration tests generated a file named generated_main.dart under .dart_tool/flutter_build/. This was working just fine when using integration tests, however, it caused unit tests to fail due to not even loading.
I managed to identify the relevant line of code in the generated file as line eight: import 'file:///tmp/flutter_tools.WJSDQT/flutter_test_listener.YHXZLS/listener.dart' as entrypoint;. The capitalized strings of random characters are indeed random, apparently referring to a temporary path that only exists for the unit test's duration. Unit tests throw (even though not always reliably): .dart_tool/flutter_build/generated_main.dart:8:8: Error: Error when reading '/tmp/flutter_tools.WJSDQT/flutter_test_listener.YHXZLS/listener.dart': No such file or directory.
Surprisingly, there seem to be no issues when deleting the generated file. I have now added a print statement to the integration tests that tells whoever ran them that they need to delete the generated file. But this is obviously not a good solution long-term. Is there a way to disable this behavior so that testing does not become unnecessarily more complicated?
My environment is Ubuntu 20.04 LTS with Flutter 2.5.0-5.1.pre on channel beta, using Android Studio 2020.3.1. I am not currently able to test for this behavior on other platforms. The program needs to run on Linux. The test package version is 1.17.10, the newest one compatible with other dependencies.
Thank you in advance for your time.

Related

Double quotes being encoded in Jest tests

I highly doubt this is a Jest issue, but it's where the issue is popping up, so here goes.
My team is using Jest for tests. Today, I was writing tests, something I hadn't done in a project repo for about a week. When running the tests today, they all failed. I noticed that all the double quotes were being encoded like so:
Expected value to be (using ===):
"{\"data\":\"Important data\"}"
Received:
"{"data":"Important data"}"
Previously, the tests all ran and passed fine.
For my own sanity, I hopped unto the master branch and ran the tests, only to receive the same result. My teammates have also run the tests on their updated master branches but didn't have any issues.
It appears to be local to my machine. I delete node_modules and package-lock.json, and even re-cloned the entire repository. Unfortunately, I am still having the same issue and I'm not sure where to look. If this issue is remotely familiar to anyone, I'd love to hear suggestions.
Some maybe relevant info:
macOS 10.14.6
iterm2 (UTF-8 encoding)
node 8.10
npm 6.11.3
jest 24.8.0
Turns out the issue was with Node.js. I had not properly configured AVN to read from .node-version, causing the tests to run using another version of node.

How to fix "Either assembly contains no tests or proper test driver has not been found."

I am getting error as mentioned Either assembly contains no tests or proper test driver has not been found.
When i enter "nunit3-console.exe project.dll".
I tried few solutions but it doesn't help me.
Assumming you have not found a new bug in the NUnit engine, then one of the two things in the message is probably true...
You are running an assembly that has no tests
You are running an assembly with tests for which there is no driver installed, IOW tests that the engine does not know how to run.
These two things are combined in one message because it's really all one thing to the engine, which is basically telling you "I can't find anything that looks like a test to me."
Most likely, you do not have any NUnit3 tests, because knowledge of those is built into the engine itself. So, I would guess you are either running NUnit V2 tests or tests from some foreign framework, like xunit or microsoft test.
For more of an answer, please tell us what kind of tests you are running. What testing framework (and version) do your tests reference? If you are running NUnit V2 tests, do you have the V2 Framework Driver extension installed?
So... maybe there is a bug in the NUnit engine.
I had this exact same error message on my build server. At the same time the tests were running fine in Visual Studio (2015 with Resharper).
This happened when I started converting existing xunit to nunit tests in an assembly. As soon as I removed the last xunit test, the error went away.
Try to comment out everything except NUnit tests to see if this fixes the problem for you.

SimpleAuthencation throwing "Failed to reflect on the current domain's Assemblies while searching for plugins"

I have a NancyFX web project using SimpleAuthentication that works fine when self-hosting from the terminal. When I self-host from unit tests (NUnit runner with Xamarin Studio), I receive exception "Failed to reflect on the current domain's Assemblies while searching for plugin" with error message "Could not load file or assembly or one of its dependencies." repeated many times.
Any idea why this would fail? This looks like the code throwing the exception is at https://github.com/SimpleAuthentication/SimpleAuthentication/blob/master/Code/SimpleAuthentication.Core/ReflectionHelpers.cs. I tried a IntPtr.Size measurement to make sure they are running in the same 32/64 bitness in both cases (it is running 32-bit).
UPDATE: Per recommendation, I tried to run some prerelease builds to the same resulting, ending up with these binaries:
./Nancy.1.3-Pre1524/lib/net40/Nancy.dll
./Nancy.Authentication.Forms.1.3-Pre1524/lib/net40/Nancy.Authentication.Forms.dll
./Nancy.FlashMessages.1.0.4.0/lib/net45/Nancy.FlashMessages.dll
./Nancy.FlashMessages.Razor.1.0.4.0/lib/net45/Nancy.FlashMessages.Razor.dll
./Nancy.Hosting.Self.1.3-Pre1524/lib/net40/Nancy.Hosting.Self.dll
./Nancy.SimpleAuthentication.0.3.14/lib/net40/Nancy.SimpleAuthentication.dll
./Nancy.Viewengines.Razor.1.3-Pre1524/BuildProviders/Nancy.ViewEngines.Razor.BuildProviders.dll
./Nancy.Viewengines.Razor.1.3-Pre1524/lib/net40/Nancy.ViewEngines.Razor.dll
UPDATE: Running the ReflectionHelpers.cs code in isolation shows that the only DLL failing to load is MonoDevelop.NUnit. The NUnit dll is unneeded for this part anyhow.
I suppose I should contemplate https://github.com/SimpleAuthentication/SimpleAuthentication/issues/144
I fixed this with GetLoadableTypes from this post from #haacked http://haacked.com/archive/2012/07/23/get-all-types-in-an-assembly.aspx/
And here it's the PR (https://github.com/SimpleAuthentication/SimpleAuthentication/pull/171)
I didn't had the problem with Nunit I had the problem with Microsoft.Owin.Security.DataProtection.DpapiDataProtector that it's not implemented in Mono....

XCode doesn't finish test build while at "Run Script" phase

When trying to build the unit tests created using the default XCode Unit Test bundle target, it looks like it's stuck on the "Run custom shell script 'Run Script'" phase.
I also notice a high cpu usage on process "otest" to the point where the fans kick in within seconds.
The only useful message I see when expanding the line is
/Developer/Tools/RunPlatformUnitTests.include:419: note: Running tests for architecture 'i386' (GC OFF)
Couldn't open shared capabilities memory GSCapabilities (No such file or directory)
The only option I have at that time is to stop the build.
Have to say I was running unit tests perfectly fine up to this moment but can't say for sure what I did to cause that.
That's on XCode 3.2.4
After updating to 3.2.5 now the run script does fail with an error
Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/Developer/usr/bin/otest' exited abnormally with code 138 (it may have crashed).
Guess they problem is related?
Did find some answers on SO about how exception handling now works differently when using NSInvocation (which otest seems to use) but not really a solution to this.
I had this happen to me. I made it go away by scrapping my old testing target profile, creating a new one, and pointing all my tests to it. I was too frustrated to compare the profiles line by line to figure out what had changed.
This looks like an infinite loop to me. Try adding some NSLog statements and/or debugging your tests with gdb (by adding otest as a custom executable).
This happened to me after updating to Xcode 9 and using script for updating localizable strings file, a minor bug caused the script to never finish. After updating BartyCrouch, everything worked normally.
https://github.com/Flinesoft/BartyCrouch/issues/66

NUnit vs MSTest - a fickle TDD novice's experiences with both of them

There are a ton of questions here on SO regarding NUnit vs. MSTest, and I have read quite a few of them. I think my question here is slightly different enough to post separately.
When I started to use C#, I never even considered looking at MSTest because I was so used to not having it available when I was using C++ previously. I basically forgot all about it. :) So I started with NUnit, and loved it. Tests were very easy to set up, and testing wasn't too painful -- just launch the IDE and run the tests!
As many here have pointed out, NUnit has frequent updates, while MSTest is only updated as often as the IDE. That's not necessarily a problem if you don't need to be on the bleeding edge of TDD (which I'm not), but the problem I was having with frequent updates is keeping all of the systems up-to-date. I use about four or five different PCs daily, and while updating all of them isn't a huge deal, I was hoping for a way to make my code compile properly on systems with an older version of NUnit. Since my project referenced the NUnit install folder, when I upgraded the framework, any computers with the older framework installed would no longer be able to compile my project. I tried to combat the problem by created a common folder in SVN that had just the NUnit DLLs, but even then it would somehow complain about the version number of the binary. Is there a way to get around this issue? This is what made me stop using the first time.
Then one day I remembered MSTest, and decided to give it a try. I loved that it was integrated into the IDE. CTRL-R,CTRL-A, all tests run. How simple! But then I saw that the types of tests available in MSTest were pretty limited. I didn't know how many I'd actually really need, but I figured I should go back to NUnit, and I did.
About now I was starting to have to debug unit tests, and the only way I could figure out how to do it in NUnit was to set NUnit as the startup application, then set breakpoints in my tests. Then in the NUnit GUI, I would run the tests to hit the breakpoints. This was a complete PITA. I then looked at the MSTest GUI again, and saw that I could just click Debug there and it would execute my tests! WOW! Now that was the killer feature that swayed me back in favor of MSTest.
Right now, I'm back using MSTest. Unfortunately, today I started to think about daily builds and did some searching on Tinderbox, which is the only tool I had heard of before for this sort of thing. This then opened up my eyes to other tools like buildbot and TFS. So the problem here is that I think MSTest is guaranteed to lock me into TFS for automated daily builds, or continuous integration, or whatever the buzzword is. My company can't afford to get locked into MS-only solutions (other than VS), so I want to examine other choices.
I'm perfectly fine to go back to NUnit. I'm not thrilled about rewriting 100+ unit tests, but that's the way it goes. However, I'd really love for someone to explain how to squash those two issues of mine, which in summary are:
how do I setup NUnit and my project so that I don't have to keep upgrading it on every system to make my project build?
how do I get easier debugging of unit tests? My approach was a pain because I'd have to keep switching between NUnit and the default app to test / run my application. I saw a post here on SO that mentioned NUnitIt on codeplex, but I haven't any experience with it.
UPDATE -- I'm comparing stuff in my development VM, and so far, NUnitit is quite nice. It's easy to install (one click), and I just point it to whatever NUnit binaries are in my SVN externals folder. Not bad! I also went into VS -> Tools -> Options -> Keyboard and changed my mapping for CTRL-R,CTRL-A to map to NUnitit.Connect.DebugGUI. Not perfect since I haven't figured out how to make NUnit automatically run the tests when it's opened, but it's pretty good. And debugging works as it should now!
UPDATE #2 -- I installed TestDriven.Net and gave it a quick run through. Overall, I like it a lot better than NUnitit, but at the moment, NUnitit wins because it's free, and since it also works with NUnit, it will allow me to "upgrade" to TestDriven.Net when the time comes. The thing I like most about TestDriven.Net is that when I double click on the failed test, it takes me right to the line in the test that had failed, while NUnit + NUnitit doesn't seem to be capable of this. Has anyone been able to make this link between the NUnit GUI and the VS IDE happen?
Many projects I've worked on have included a copy of the specific version of NUnit (or xUnit.net, whatever) in a "lib" or "extrernal" or "libraries" folder in their source control, and reference that location for building all of their tests. This greatly reduces the "upgrade everyone" headache, since you really don't need to install NUnit or xUnit.net to use it.
This approach will still let you use something like TestDriven.Net to execute the tests, run the tests in a debugger, etc.
For easier debugging (and running, too) of unit tests I recommend checking out TestDriven.Net. The "Test With > Debugger" feature is so handy. The personal version is free.
Have you played with the "Specific Version" property on the NUnit.framework reference? We keep ours set to true so that the tests that are coded for a given nunit version require that specific version to execute.
I'm not sure how it will handle, for example, if you had 2.5 on your machine but another machine only had 2.4 - would .NET bind to the 2.4 version happily or will it only bind from earlier versions to later versions of an assembly (e.g. compiled against 2.4, but 2.5 availale at runtime?)