Open Thieum opened 4 years ago
S7NetPlus uses Snap7 in its unit tests. I think most of the code for that is in https://github.com/S7NetPlus/s7netplus/blob/develop/S7.Net.UnitTest/Helpers/S7TestServer.cs . Your implementation using Snap7.Managed might be better though.
I was able to get that Snap7 unit test in S7NetPlus working on net core linux and windows in https://github.com/S7NetPlus/s7netplus/pull/318, while also removing the Port 102 dependency. That makes it a bit easier to setup a test environment and do multi-platform testing.
I don't think all of that is ever a replacement for true integration testing using S7 PLCs, but it could definitely be a part of automated unit/integration tests.
It's actually a really interesting problem on its own. If I implement server side support in Sally7, I intend to share as much code as possible for the data structs. Evidently what happens if I change a struct is that both client and server will change, so the question is how valuable a unit test against Sally7 as server would be. On the other hand testing against another S7 implementation should not be affected by internal refactorings, so there's something to say for that as well. Still, I don't feel like introducing a dependency on Snap7 in any way, I guess that library just doesn't live up to my expectations of code quality.
As far as proper unit testing is concerned, it would mostly be important to actually separate out the units. Currently there's a mixture of connection management and structuring protocol data in the S7Connection
class, neither of which can currently be tested without the other. It's not high on my to do list, but I guess it's something I will change. When it has changed we can just do writes against a MemoryStream
(or whatever, I'm actually playing with PipeReader
this evening) and verify the data to ensure protocol validity. Connection management (as far as it exists) could then be tested separately as well.
Anyway, I'm somehow currently very motivated to make some next steps with Sally7 (and possibly S7NetPlus as well), so maybe the next few days/weeks might provide some improvements.
(As briefly discussed through email in the end of 2019) Sally7 provides a great experience for the client part of the S7 protocol, but there is no server component at the moment. It means you need a real server or use another library to create an emulator if you want to test your code.
I've been using Snap7 in the mean time, but it would be nice to have a complete Sally7 experience for the S7 protocol.
Here an example adapted from the code provided by Snap7 for a basic S7 server emulator, using Snap7: